Asterisk - The Open Source Telephony Project
21.4.1
|
Cross-platform console channel driver. More...
#include "asterisk.h"
#include <signal.h>
#include <portaudio.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/causes.h"
#include "asterisk/cli.h"
#include "asterisk/musiconhold.h"
#include "asterisk/callerid.h"
#include "asterisk/astobj2.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/format_cache.h"
Go to the source code of this file.
Data Structures | |
struct | console_pvt |
Console pvt structure. More... | |
Macros | |
#define | console_pvt_lock(pvt) ao2_lock(pvt) |
lock a console_pvt struct | |
#define | console_pvt_unlock(pvt) ao2_unlock(pvt) |
unlock a console_pvt struct | |
#define | INPUT_CHANNELS 1 |
Mono Input. | |
#define | NUM_PVT_BUCKETS 7 |
#define | NUM_SAMPLES 320 |
The number of samples to configure the portaudio stream for. More... | |
#define | OUTPUT_CHANNELS 1 |
Mono Output. | |
#define | SAMPLE_RATE 16000 |
The sample rate to request from PortAudio. More... | |
#define | TEXT_SIZE 256 |
Maximum text message length. More... | |
#define | V_BEGIN " --- <(\"<) --- " |
Dance, Kirby, Dance! | |
#define | V_END " --- (>\")> ---\n" |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static char * | ast_ext_ctx (struct console_pvt *pvt, const char *src, char **ext, char **ctx) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | build_device (struct ast_config *cfg, const char *name) |
static char * | cli_console_active (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_console_answer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
answer command from the console | |
static char * | cli_console_autoanswer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_console_dial (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_console_flash (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_console_hangup (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_console_mute (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_console_sendtext (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
Console send text CLI command. More... | |
static char * | cli_list_available (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | cli_list_devices (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static struct ast_channel * | console_new (struct console_pvt *pvt, const char *ext, const char *ctx, int state, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor) |
static void | destroy_pvts (void) |
static struct console_pvt * | find_pvt (const char *name) |
static struct console_pvt * | get_active_pvt (void) |
static int | init_pvt (struct console_pvt *pvt, const char *name) |
static int | load_config (int reload) |
Load the configuration. More... | |
static int | load_module (void) |
Load the module. More... | |
static int | open_stream (struct console_pvt *pvt) |
static int | pvt_cmp_cb (void *obj, void *arg, int flags) |
static void | pvt_destructor (void *obj) |
static int | pvt_hash_cb (const void *obj, const int flags) |
static int | pvt_mark_destroy_cb (void *obj, void *arg, int flags) |
static struct console_pvt * | ref_pvt (struct console_pvt *pvt) |
static int | reload (void) |
static void | set_active (struct console_pvt *pvt, const char *value) |
static void | set_pvt_defaults (struct console_pvt *pvt) |
Set default values for a pvt struct. More... | |
static int | start_stream (struct console_pvt *pvt) |
static int | stop_stream (struct console_pvt *pvt) |
static void | stop_streams (void) |
static void | store_callerid (struct console_pvt *pvt, const char *value) |
static void | store_config_core (struct console_pvt *pvt, const char *var, const char *value) |
Store a configuration parameter in a pvt struct. More... | |
static void * | stream_monitor (void *data) |
Stream monitor thread. More... | |
static int | unload_module (void) |
static struct console_pvt * | unref_pvt (struct console_pvt *pvt) |
static struct ast_channel * | console_request (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause) |
static int | console_digit_begin (struct ast_channel *c, char digit) |
static int | console_digit_end (struct ast_channel *c, char digit, unsigned int duration) |
static int | console_text (struct ast_channel *c, const char *text) |
static int | console_hangup (struct ast_channel *c) |
static int | console_answer (struct ast_channel *c) |
static struct ast_frame * | console_read (struct ast_channel *chan) |
Implementation of the ast_channel_tech read() callback. More... | |
static int | console_call (struct ast_channel *c, const char *dest, int timeout) |
static int | console_write (struct ast_channel *chan, struct ast_frame *f) |
static int | console_indicate (struct ast_channel *chan, int cond, const void *data, size_t datalen) |
static int | console_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "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 = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DRIVER, } |
static ast_rwlock_t | active_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } |
static struct console_pvt * | active_pvt |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_console [] |
static const char | config_file [] = "console.conf" |
static struct ast_channel_tech | console_tech |
static struct ast_jb_conf | default_jbconf |
Global jitterbuffer configuration. More... | |
static struct ast_jb_conf | global_jbconf |
static struct console_pvt | globals |
static ast_mutex_t | globals_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
static struct ao2_container * | pvts |
Cross-platform console channel driver.
Portaudio http://www.portaudio.com/
To install portaudio v19 from svn, check it out using the following command:
Definition in file chan_console.c.
#define NUM_SAMPLES 320 |
The number of samples to configure the portaudio stream for.
320 samples (20 ms) is the most common frame size in Asterisk. So, the code in this module reads 320 sample frames from the portaudio stream and queues them up on the Asterisk channel. Frames of any size can be written to a portaudio stream, but the portaudio documentation does say that for high performance applications, the data should be written to Pa_WriteStream in the same size as what is used to initialize the stream.
Definition at line 96 of file chan_console.c.
Referenced by stream_monitor().
#define SAMPLE_RATE 16000 |
The sample rate to request from PortAudio.
Definition at line 84 of file chan_console.c.
Referenced by stream_monitor().
#define TEXT_SIZE 256 |
Maximum text message length.
Definition at line 109 of file chan_console.c.
Referenced by cli_console_sendtext().
|
static |
split a string in extension-context, returns pointers to malloc'ed strings. If we do not have 'overridecontext' then the last @ is considered as a context separator, and the context is overridden. This is usually not very necessary as you can play with the dialplan, and it is nice not to need it because you have '@' in SIP addresses. Return value is the buffer address.
Definition at line 682 of file chan_console.c.
References ast_strdup, and console_pvt::overridecontext.
|
static |
Console send text CLI command.
Definition at line 1121 of file chan_console.c.
References ast_cli_entry::args, AST_FRAME_TEXT, ast_join, ast_queue_frame(), ast_cli_entry::command, ast_frame::datalen, ast_frame::frametype, ast_frame::len, console_pvt::owner, TEXT_SIZE, and ast_cli_entry::usage.
|
static |
Definition at line 425 of file chan_console.c.
References ao2_ref, ast_channel_alloc, ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin16, ast_hangup(), ast_jb_configure(), ast_pbx_start(), AST_STATE_DOWN, console_pvt::cid_name, console_pvt::cid_num, console_pvt::language, console_pvt::name, and console_pvt::owner.
Referenced by console_request().
|
static |
Implementation of the ast_channel_tech read() callback.
Calling this function is harmless. However, if it does get called, it is an indication that something weird happened that really shouldn't have and is worth looking into.
Why should this function not get called? Well, let me explain. There are a couple of ways to pass on audio that has come from this channel. The way that this channel driver uses is that once the audio is available, it is wrapped in an ast_frame and queued onto the channel using ast_queue_frame().
The other method would be signalling to the core that there is audio waiting, and that it needs to call the channel's read() callback to get it. The way the channel gets signalled is that one or more file descriptors are placed in the fds array on the ast_channel which the core will poll() on. When the fd indicates that input is available, the read() callback is called. This is especially useful when there is a dedicated file descriptor where the audio is read from. An example would be the socket for an RTP stream.
Definition at line 577 of file chan_console.c.
References ast_debug, and ast_null_frame.
|
static |
Channel Technology Callbacks
Definition at line 473 of file chan_console.c.
References ast_format_cap_get_names(), ast_format_cap_iscompatible(), AST_FORMAT_CAP_NAMES_LEN, AST_STATE_DOWN, ast_channel_tech::capabilities, console_new(), console_pvt_lock, console_pvt_unlock, and console_pvt::owner.
|
static |
Load the configuration.
reload | if this was called due to a reload |
0 | success |
-1 | failure |
Definition at line 1431 of file chan_console.c.
References ao2_callback, ast_category_browse(), ast_config_destroy(), ast_config_load, config_file, ast_variable::name, ast_variable::next, OBJ_NODATA, set_pvt_defaults(), store_config_core(), and ast_variable::value.
Referenced by load_module().
|
static |
Load the module.
Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 1528 of file chan_console.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_channel_register(), ast_channel_unregister(), ast_cli_register_multiple, ast_cli_unregister_multiple(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin16, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_channel_tech::capabilities, and load_config().
|
static |
Set default values for a pvt struct.
Definition at line 1276 of file chan_console.c.
References ast_string_field_set, console_pvt::autoanswer, console_pvt::cid_name, console_pvt::cid_num, console_pvt::context, console_pvt::exten, console_pvt::language, console_pvt::mohinterpret, console_pvt::overridecontext, and console_pvt::parkinglot.
Referenced by load_config().
|
static |
Store a configuration parameter in a pvt struct.
Definition at line 1324 of file chan_console.c.
References ast_jb_read_conf(), console_pvt::autoanswer, CV_BOOL, CV_END, CV_F, CV_START, and console_pvt::overridecontext.
Referenced by load_config().
|
static |
Stream monitor thread.
This function runs in its own thread to monitor data coming in from a portaudio stream. When enough data is available, it is queued up to be read from the Asterisk channel.
Definition at line 265 of file chan_console.c.
References console_pvt::abort, ast_debug, ast_format_slin16, AST_FRAME_VOICE, ast_queue_frame(), console_pvt_lock, console_pvt_unlock, ast_frame::frametype, INPUT_CHANNELS, console_pvt::name, NUM_SAMPLES, OUTPUT_CHANNELS, console_pvt::owner, SAMPLE_RATE, ast_frame::samples, console_pvt::stream, console_pvt::streamstate, and console_pvt::thread.
|
static |
Global jitterbuffer configuration.
Definition at line 186 of file chan_console.c.