84#define SAMPLE_RATE 16000
96#define NUM_SAMPLES 320
99#define INPUT_CHANNELS 1
102#define OUTPUT_CHANNELS 1
112#define V_BEGIN " --- <(\"<) --- "
113#define V_END " --- (>\")> ---\n"
175#define NUM_PVT_BUCKETS 7
189 .resync_threshold = 1000,
213 .description =
"Console Channel Driver",
228#define console_pvt_lock(pvt) ao2_lock(pvt)
231#define console_pvt_unlock(pvt) ao2_unlock(pvt)
273 .src =
"console_stream_monitor",
275 .datalen =
sizeof(
buf),
288 if (res == paNoError) {
300 int res = paInternalError;
307 PaStreamParameters input_params = {
309 .sampleFormat = paInt16,
310 .suggestedLatency = (1.0 / 50.0),
311 .device = paNoDevice,
313 PaStreamParameters output_params = {
315 .sampleFormat = paInt16,
316 .suggestedLatency = (1.0 / 50.0),
317 .device = paNoDevice,
319 PaDeviceIndex idx, num_devices, def_input, def_output;
321 if (!(num_devices = Pa_GetDeviceCount()))
324 def_input = Pa_GetDefaultInputDevice();
325 def_output = Pa_GetDefaultOutputDevice();
328 idx < num_devices && (input_params.device == paNoDevice
329 || output_params.device == paNoDevice);
332 const PaDeviceInfo *dev = Pa_GetDeviceInfo(idx);
334 if (dev->maxInputChannels) {
335 if ( (idx == def_input && !strcasecmp(pvt->
input_device,
"default")) ||
337 input_params.device = idx;
340 if (dev->maxOutputChannels) {
341 if ( (idx == def_output && !strcasecmp(pvt->
output_device,
"default")) ||
343 output_params.device = idx;
347 if (input_params.device == paNoDevice)
349 if (output_params.device == paNoDevice)
352 res = Pa_OpenStream(&pvt->
stream, &input_params, &output_params,
376 if (res != paNoError) {
378 res, Pa_GetErrorText(res));
383 res = Pa_StartStream(pvt->
stream);
384 if (res != paNoError) {
386 res, Pa_GetErrorText(res));
409 pthread_kill(pvt->
thread, SIGURG);
413 Pa_AbortStream(pvt->
stream);
414 Pa_CloseStream(pvt->
stream);
436 ext, ctx, assignedids, requestor, 0,
"Console/%s", pvt->
name))) {
454 ast_channel_language_set(chan, pvt->
language);
579 ast_debug(1,
"I should not be called ...\n");
603 ast_verb(1,
V_BEGIN "Type 'console answer' to answer, or use the 'autoanswer' option "
604 "for future calls" V_END);
666 pvt->
owner = newchan;
689 if (src && *src !=
'\0')
697 *ctx = strrchr(*
ext,
'@');
724 e->
command =
"console {set|show} autoanswer [on|off]";
726 "Usage: console {set|show} autoanswer [on|off]\n"
727 " Enables or disables autoanswer feature. If used without\n"
728 " argument, displays the current on/off status of autoanswer.\n"
729 " The default value of autoanswer is in 'oss.conf'.\n";
738 ast_cli(
a->fd,
"No console device is set as active.\n");
742 if (
a->argc == e->
args - 1) {
748 if (
a->argc != e->
args) {
753 if (!strcasecmp(
a->argv[e->
args-1],
"on"))
755 else if (!strcasecmp(
a->argv[e->
args - 1],
"off"))
772 "Usage: console flash\n"
773 " Flashes the call currently placed on the console.\n";
779 if (
a->argc != e->
args) {
785 ast_cli(
a->fd,
"No console device is set as active\n");
790 ast_cli(
a->fd,
"No call to flash\n");
807 const char *mye =
NULL, *myc =
NULL;
813 "Usage: console dial [extension[@context]]\n"
814 " Dials a given extension (and context if specified)\n";
820 if (
a->argc > e->
args + 1) {
826 ast_cli(
a->fd,
"No console device is currently set as active\n");
835 if (
a->argc == e->
args) {
836 ast_cli(
a->fd,
"Already in a call. You can only dial digits until you hangup.\n");
840 s =
a->argv[e->
args];
842 for (i = 0; i < strlen(s); i++) {
851 if (
a->argc == e->
args + 1) {
856 ast_debug(1,
"provided '%s', exten '%s' context '%s'\n",
857 a->argv[e->
args], mye, myc);
872 ast_cli(
a->fd,
"No such extension '%s' in context '%s'\n", mye, myc);
888 "Usage: console hangup\n"
889 " Hangs up any call currently placed on the console.\n";
895 if (
a->argc != e->
args) {
901 ast_cli(
a->fd,
"No console device is set as active\n");
906 ast_cli(
a->fd,
"No call to hang up\n");
927 e->
command =
"console {mute|unmute}";
929 "Usage: console {mute|unmute}\n"
930 " Mute/unmute the microphone.\n";
936 if (
a->argc != e->
args) {
942 ast_cli(
a->fd,
"No console device is set as active\n");
946 s =
a->argv[e->
args-1];
947 if (!strcasecmp(s,
"mute"))
949 else if (!strcasecmp(s,
"unmute"))
955 pvt->
muted ?
"Muted" :
"Unmuted");
964 PaDeviceIndex idx, num, def_input, def_output;
967 e->
command =
"console list available";
969 "Usage: console list available\n"
970 " List all available devices.\n";
975 if (
a->argc != e->
args)
979 "=============================================================\n"
980 "=== Available Devices =======================================\n"
981 "=============================================================\n"
984 num = Pa_GetDeviceCount();
990 def_input = Pa_GetDefaultInputDevice();
991 def_output = Pa_GetDefaultOutputDevice();
992 for (idx = 0; idx < num; idx++) {
993 const PaDeviceInfo *dev = Pa_GetDeviceInfo(idx);
996 ast_cli(
a->fd,
"=== ---------------------------------------------------------\n"
997 "=== Device Name: %s\n", dev->
name);
998 if (dev->maxInputChannels)
999 ast_cli(
a->fd,
"=== ---> %sInput Device\n", (idx == def_input) ?
"Default " :
"");
1000 if (dev->maxOutputChannels)
1001 ast_cli(
a->fd,
"=== ---> %sOutput Device\n", (idx == def_output) ?
"Default " :
"");
1002 ast_cli(
a->fd,
"=== ---------------------------------------------------------\n===\n");
1005 ast_cli(
a->fd,
"=============================================================\n\n");
1016 e->
command =
"console list devices";
1018 "Usage: console list devices\n"
1019 " List all configured devices.\n";
1024 if (
a->argc != e->
args)
1028 "=============================================================\n"
1029 "=== Configured Devices ======================================\n"
1030 "=============================================================\n"
1037 ast_cli(
a->fd,
"=== ---------------------------------------------------------\n"
1038 "=== Device Name: %s\n"
1039 "=== ---> Active: %s\n"
1040 "=== ---> Input Device: %s\n"
1041 "=== ---> Output Device: %s\n"
1042 "=== ---> Context: %s\n"
1043 "=== ---> Extension: %s\n"
1044 "=== ---> CallerID Num: %s\n"
1045 "=== ---> CallerID Name: %s\n"
1046 "=== ---> MOH Interpret: %s\n"
1047 "=== ---> Language: %s\n"
1048 "=== ---> Parkinglot: %s\n"
1049 "=== ---> Muted: %s\n"
1050 "=== ---> Auto-Answer: %s\n"
1051 "=== ---> Override Context: %s\n"
1052 "=== ---------------------------------------------------------\n===\n",
1064 ast_cli(
a->fd,
"=============================================================\n\n");
1077 e->
command =
"console answer";
1079 "Usage: console answer\n"
1080 " Answers an incoming call on the console channel.\n";
1089 ast_cli(
a->fd,
"No console device is set as active\n");
1093 if (
a->argc != e->
args) {
1099 ast_cli(
a->fd,
"No one is calling us\n");
1128 .src =
"console_send_text",
1133 e->
command =
"console send text";
1135 "Usage: console send text <message>\n"
1136 " Sends a text message for display on the remote terminal.\n";
1144 ast_cli(
a->fd,
"No console device is set as active\n");
1148 if (
a->argc < e->
args + 1) {
1199 e->
command =
"console {set|show} active";
1201 "Usage: console {set|show} active [<device>]\n"
1202 " Set or show the active console device for the Asterisk CLI.\n";
1205 if (
a->pos == e->
args) {
1211 if (++x >
a->n && !strncasecmp(pvt->
name,
a->word, strlen(
a->word)))
1224 if (
a->argc < e->
args)
1231 ast_cli(
a->fd,
"No device is currently set as the active console device.\n");
1234 ast_cli(
a->fd,
"The active console device is '%s'.\n", pvt->
name);
1243 ast_cli(
a->fd,
"Could not find a device called '%s'.\n",
a->argv[e->
args]);
1250 ast_cli(
a->fd,
"The active console device has been set to '%s'\n", pvt->
name);
1313 cid_num,
sizeof(cid_num));
1460 if (strcasecmp(
context,
"general"))
1547 res = Pa_Initialize();
1548 if (res != paNoError) {
1550 res, Pa_GetErrorText(res));
1551 goto return_error_pa_init;
1556 goto return_error_chan_reg;
1560 goto return_error_cli_reg;
1564return_error_cli_reg:
1566return_error_chan_reg:
1568return_error_pa_init:
void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
Configures a jitterbuffer on a channel.
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
Sets jitterbuffer configuration property.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ao2_iterator_next(iter)
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
#define ao2_unlink(container, obj)
Remove an object from a container.
#define ao2_find(container, arg, flags)
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen)
Internal Asterisk hangup causes.
#define AST_CAUSE_SWITCH_CONGESTION
#define V_BEGIN
Dance, Kirby, Dance!
static struct console_pvt * ref_pvt(struct console_pvt *pvt)
static char * cli_console_autoanswer(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 int open_stream(struct console_pvt *pvt)
static void build_device(struct ast_config *cfg, const char *name)
#define console_pvt_lock(pvt)
lock a console_pvt struct
static void destroy_pvts(void)
static struct ast_jb_conf default_jbconf
Global jitterbuffer configuration.
static void stop_streams(void)
static void set_pvt_defaults(struct console_pvt *pvt)
Set default values for a pvt struct.
static struct console_pvt * active_pvt
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 char * cli_console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
answer command from the console
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 void pvt_destructor(void *obj)
static int pvt_hash_cb(const void *obj, const int flags)
static char * cli_console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define SAMPLE_RATE
The sample rate to request from PortAudio.
#define OUTPUT_CHANNELS
Mono Output.
static char * cli_console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
static int init_pvt(struct console_pvt *pvt, const char *name)
static ast_rwlock_t active_lock
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
static char * cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int console_call(struct ast_channel *c, const char *dest, int timeout)
static int pvt_cmp_cb(void *obj, void *arg, int flags)
static void * stream_monitor(void *data)
Stream monitor thread.
static struct ao2_container * pvts
static int console_digit_begin(struct ast_channel *c, char digit)
#define INPUT_CHANNELS
Mono Input.
static char * cli_console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Console send text CLI command.
static int console_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen)
static int stop_stream(struct console_pvt *pvt)
static int console_write(struct ast_channel *chan, struct ast_frame *f)
static struct ast_frame * console_read(struct ast_channel *chan)
Implementation of the ast_channel_tech read() callback.
static char * cli_list_available(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int console_hangup(struct ast_channel *c)
static int console_answer(struct ast_channel *c)
static void set_active(struct console_pvt *pvt, const char *value)
static int console_text(struct ast_channel *c, const char *text)
static struct ast_jb_conf global_jbconf
static char * ast_ext_ctx(struct console_pvt *pvt, const char *src, char **ext, char **ctx)
static struct ast_cli_entry cli_console[]
static const char config_file[]
static struct console_pvt globals
static char * cli_list_devices(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct console_pvt * get_active_pvt(void)
static int load_module(void)
Load the module.
static ast_mutex_t globals_lock
static void store_config_core(struct console_pvt *pvt, const char *var, const char *value)
Store a configuration parameter in a pvt struct.
static int pvt_mark_destroy_cb(void *obj, void *arg, int flags)
static int console_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
static struct ast_channel_tech console_tech
static int unload_module(void)
static int load_config(int reload)
Load the configuration.
static char * cli_console_active(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct console_pvt * find_pvt(const char *name)
static int console_digit_end(struct ast_channel *c, char digit, unsigned int duration)
#define NUM_SAMPLES
The number of samples to configure the portaudio stream for.
static int start_stream(struct console_pvt *pvt)
#define TEXT_SIZE
Maximum text message length.
static void store_callerid(struct console_pvt *pvt, const char *value)
static char language[MAX_LANGUAGE]
static char mohinterpret[MAX_MUSICCLASS]
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
void * ast_channel_tech_pvt(const struct ast_channel *chan)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
#define ast_channel_unlock(chan)
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
#define CV_STRFIELD(__x, __obj, __field)
#define CV_END
close a variable parsing block
#define CV_F(__pattern, __body)
call a generic function if the name matches.
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
#define CV_BOOL(__x, __dst)
helper macros to assign the value to a BOOL, UINT, static string and dynamic string
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
ast_control_frame_type
Internal control frame subtype field values.
@ AST_CONTROL_PVT_CAUSE_CODE
struct ast_frame ast_null_frame
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
#define ast_rwlock_wrlock(a)
#define AST_PTHREADT_NULL
#define ast_rwlock_rdlock(a)
#define AST_RWLOCK_DEFINE_STATIC(rwlock)
#define ast_mutex_unlock(a)
#define ast_rwlock_unlock(a)
#define ast_mutex_lock(a)
#define AST_MUTEX_DEFINE_STATIC(mutex)
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_CHANNEL_DRIVER
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Core PBX routines and definitions.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_alloca(init_len)
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
#define ast_join(s, len, w)
Join an array of strings into a single string.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Structure to pass both assignedid values to channel drivers.
Structure to describe a channel "technology", ie a channel driver See for examples:
struct ast_format_cap * capabilities
Main Channel structure associated with a channel.
descriptor for a cli entry.
int args
This gets set in ast_cli_register()
Structure used to handle boolean flags.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
General jitterbuffer configuration.
unsigned int flags
Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
const ast_string_field mohinterpret
const ast_string_field language
const ast_string_field cid_num
unsigned int overridecontext
const ast_string_field context
const ast_string_field input_device
const ast_string_field parkinglot
const ast_string_field output_device
struct ast_channel * owner
const ast_string_field exten
const ast_string_field name
const ast_string_field cid_name
#define ast_pthread_create_background(a, b, c, d)