67 #include <portaudio.h> 86 #define SAMPLE_RATE 16000 98 #define NUM_SAMPLES 320 101 #define INPUT_CHANNELS 1 104 #define OUTPUT_CHANNELS 1 111 #define TEXT_SIZE 256 114 #define V_BEGIN " --- <(\"<) --- " 115 #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),
280 pthread_testcancel();
284 pthread_testcancel();
290 if (res == paNoError)
299 int res = paInternalError;
306 PaStreamParameters input_params = {
308 .sampleFormat = paInt16,
309 .suggestedLatency = (1.0 / 50.0),
310 .device = paNoDevice,
312 PaStreamParameters output_params = {
314 .sampleFormat = paInt16,
315 .suggestedLatency = (1.0 / 50.0),
316 .device = paNoDevice,
318 PaDeviceIndex idx, num_devices, def_input, def_output;
320 if (!(num_devices = Pa_GetDeviceCount()))
323 def_input = Pa_GetDefaultInputDevice();
324 def_output = Pa_GetDefaultOutputDevice();
327 idx < num_devices && (input_params.device == paNoDevice
328 || output_params.device == paNoDevice);
331 const PaDeviceInfo *dev = Pa_GetDeviceInfo(idx);
333 if (dev->maxInputChannels) {
334 if ( (idx == def_input && !strcasecmp(pvt->
input_device,
"default")) ||
336 input_params.device = idx;
339 if (dev->maxOutputChannels) {
340 if ( (idx == def_output && !strcasecmp(pvt->
output_device,
"default")) ||
342 output_params.device = idx;
346 if (input_params.device == paNoDevice)
348 if (output_params.device == paNoDevice)
351 res = Pa_OpenStream(&pvt->
stream, &input_params, &output_params,
375 if (res != paNoError) {
377 res, Pa_GetErrorText(res));
382 res = Pa_StartStream(pvt->
stream);
383 if (res != paNoError) {
385 res, Pa_GetErrorText(res));
406 pthread_cancel(pvt->
thread);
407 pthread_kill(pvt->
thread, SIGURG);
411 Pa_AbortStream(pvt->
stream);
412 Pa_CloseStream(pvt->
stream);
434 ext, ctx, assignedids, requestor, 0,
"Console/%s", pvt->
name))) {
452 ast_channel_language_set(chan, pvt->
language);
577 ast_debug(1,
"I should not be called ...\n");
601 ast_verb(1,
V_BEGIN "Type 'console answer' to answer, or use the 'autoanswer' option " 602 "for future calls" V_END);
664 pvt->
owner = newchan;
687 if (src && *src !=
'\0')
695 *ctx = strrchr(*ext,
'@');
722 e->
command =
"console {set|show} autoanswer [on|off]";
724 "Usage: console {set|show} autoanswer [on|off]\n" 725 " Enables or disables autoanswer feature. If used without\n" 726 " argument, displays the current on/off status of autoanswer.\n" 727 " The default value of autoanswer is in 'oss.conf'.\n";
736 ast_cli(a->
fd,
"No console device is set as active.\n");
751 if (!strcasecmp(a->
argv[e->
args-1],
"on"))
753 else if (!strcasecmp(a->
argv[e->
args - 1],
"off"))
770 "Usage: console flash\n" 771 " Flashes the call currently placed on the console.\n";
783 ast_cli(a->
fd,
"No console device is set as active\n");
805 const char *mye =
NULL, *myc =
NULL;
811 "Usage: console dial [extension[@context]]\n" 812 " Dials a given extension (and context if specified)\n";
824 ast_cli(a->
fd,
"No console device is currently set as active\n");
834 ast_cli(a->
fd,
"Already in a call. You can only dial digits until you hangup.\n");
840 for (i = 0; i < strlen(s); i++) {
854 ast_debug(1,
"provided '%s', exten '%s' context '%s'\n",
870 ast_cli(a->
fd,
"No such extension '%s' in context '%s'\n", mye, myc);
886 "Usage: console hangup\n" 887 " Hangs up any call currently placed on the console.\n";
899 ast_cli(a->
fd,
"No console device is set as active\n");
925 e->
command =
"console {mute|unmute}";
927 "Usage: console {mute|unmute}\n" 928 " Mute/unmute the microphone.\n";
940 ast_cli(a->
fd,
"No console device is set as active\n");
945 if (!strcasecmp(s,
"mute"))
947 else if (!strcasecmp(s,
"unmute"))
953 pvt->
muted ?
"Muted" :
"Unmuted");
962 PaDeviceIndex idx, num, def_input, def_output;
965 e->
command =
"console list available";
967 "Usage: console list available\n" 968 " List all available devices.\n";
977 "=============================================================\n" 978 "=== Available Devices =======================================\n" 979 "=============================================================\n" 982 num = Pa_GetDeviceCount();
988 def_input = Pa_GetDefaultInputDevice();
989 def_output = Pa_GetDefaultOutputDevice();
990 for (idx = 0; idx < num; idx++) {
991 const PaDeviceInfo *dev = Pa_GetDeviceInfo(idx);
994 ast_cli(a->
fd,
"=== ---------------------------------------------------------\n" 995 "=== Device Name: %s\n", dev->name);
996 if (dev->maxInputChannels)
997 ast_cli(a->
fd,
"=== ---> %sInput Device\n", (idx == def_input) ?
"Default " :
"");
998 if (dev->maxOutputChannels)
999 ast_cli(a->
fd,
"=== ---> %sOutput Device\n", (idx == def_output) ?
"Default " :
"");
1000 ast_cli(a->
fd,
"=== ---------------------------------------------------------\n===\n");
1003 ast_cli(a->
fd,
"=============================================================\n\n");
1014 e->
command =
"console list devices";
1016 "Usage: console list devices\n" 1017 " List all configured devices.\n";
1026 "=============================================================\n" 1027 "=== Configured Devices ======================================\n" 1028 "=============================================================\n" 1035 ast_cli(a->
fd,
"=== ---------------------------------------------------------\n" 1036 "=== Device Name: %s\n" 1037 "=== ---> Active: %s\n" 1038 "=== ---> Input Device: %s\n" 1039 "=== ---> Output Device: %s\n" 1040 "=== ---> Context: %s\n" 1041 "=== ---> Extension: %s\n" 1042 "=== ---> CallerID Num: %s\n" 1043 "=== ---> CallerID Name: %s\n" 1044 "=== ---> MOH Interpret: %s\n" 1045 "=== ---> Language: %s\n" 1046 "=== ---> Parkinglot: %s\n" 1047 "=== ---> Muted: %s\n" 1048 "=== ---> Auto-Answer: %s\n" 1049 "=== ---> Override Context: %s\n" 1050 "=== ---------------------------------------------------------\n===\n",
1051 pvt->
name, (pvt == active_pvt) ?
"Yes" :
"No",
1062 ast_cli(a->
fd,
"=============================================================\n\n");
1075 e->
command =
"console answer";
1077 "Usage: console answer\n" 1078 " Answers an incoming call on the console channel.\n";
1087 ast_cli(a->
fd,
"No console device is set as active\n");
1097 ast_cli(a->
fd,
"No one is calling us\n");
1126 .src =
"console_send_text",
1131 e->
command =
"console send text";
1133 "Usage: console send text <message>\n" 1134 " Sends a text message for display on the remote terminal.\n";
1142 ast_cli(a->
fd,
"No console device is set as active\n");
1197 e->
command =
"console {set|show} active";
1199 "Usage: console {set|show} active [<device>]\n" 1200 " Set or show the active console device for the Asterisk CLI.\n";
1209 if (++x > a->
n && !strncasecmp(pvt->
name, a->
word, strlen(a->
word)))
1229 ast_cli(a->
fd,
"No device is currently set as the active console device.\n");
1232 ast_cli(a->
fd,
"The active console device is '%s'.\n", pvt->
name);
1248 ast_cli(a->
fd,
"The active console device has been set to '%s'\n", pvt->
name);
1311 cid_num,
sizeof(cid_num));
1414 if (active_pvt == pvt)
1458 if (strcasecmp(context,
"general"))
1545 res = Pa_Initialize();
1546 if (res != paNoError) {
1548 res, Pa_GetErrorText(res));
1549 goto return_error_pa_init;
1554 goto return_error_chan_reg;
1558 goto return_error_cli_reg;
1562 return_error_cli_reg:
1564 return_error_chan_reg:
1566 return_error_pa_init:
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
struct ast_variable * next
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
static int open_stream(struct console_pvt *pvt)
static char * cli_console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Console send text CLI command.
#define ast_rwlock_rdlock(a)
Main Channel structure associated with a channel.
static int pvt_hash_cb(const void *obj, const int flags)
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk main include file. File version handling, generic pbx functions.
#define AST_RWLOCK_DEFINE_STATIC(rwlock)
static int console_call(struct ast_channel *c, const char *dest, int timeout)
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
static void stop_streams(void)
int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen)
static void build_device(struct ast_config *cfg, const char *name)
const ast_string_field cid_num
static char * cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * cli_console_active(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
#define ast_join(s, len, w)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
void * ast_channel_tech_pvt(const struct ast_channel *chan)
static char * cli_console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define AST_CAUSE_SWITCH_CONGESTION
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
static int console_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
const ast_string_field context
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
static void set_pvt_defaults(struct console_pvt *pvt)
Set default values for a pvt struct.
static struct ast_jb_conf global_jbconf
static char * cli_console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
descriptor for a cli entry.
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
#define ao2_callback(c, flags, cb_fn, arg)
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
Sets jitterbuffer configuration property.
#define CONFIG_STATUS_FILEINVALID
static char * cli_console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Structure for variables, used for configurations and for channel variables.
unsigned int overridecontext
Structure to pass both assignedid values to channel drivers.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static int console_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen)
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static int load_config(int reload)
Load the configuration.
ast_control_frame_type
Internal control frame subtype field values.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
static int start_stream(struct console_pvt *pvt)
#define ast_mutex_lock(a)
struct ast_channel * owner
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 ...
static int console_digit_begin(struct ast_channel *c, char digit)
#define ast_str_alloca(init_len)
#define ast_strdup(str)
A wrapper for strdup()
const ast_string_field parkinglot
static int unload_module(void)
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
static ast_mutex_t globals_lock
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
#define CV_END
close a variable parsing block
static char * cli_list_available(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define SAMPLE_RATE
The sample rate to request from PortAudio.
void ast_cli(int fd, const char *fmt,...)
static int console_hangup(struct ast_channel *c)
#define ast_rwlock_unlock(a)
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
#define ast_verb(level,...)
struct ast_frame_subclass subclass
static int console_digit_end(struct ast_channel *c, char digit, unsigned int duration)
static void store_callerid(struct console_pvt *pvt, const char *value)
int args
This gets set in ast_cli_register()
static struct ast_frame * console_read(struct ast_channel *chan)
#define ast_strlen_zero(foo)
static char * ast_ext_ctx(struct console_pvt *pvt, const char *src, char **ext, char **ctx)
static struct ast_jb_conf default_jbconf
Global jitterbuffer configuration.
#define ast_pthread_create_background(a, b, c, d)
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
static struct ast_channel_tech console_tech
#define CV_F(__pattern, __body)
call a generic function if the name matches.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_config_load(filename, flags)
Load a config file.
static struct ast_cli_entry cli_console[]
static int pvt_mark_destroy_cb(void *obj, void *arg, int flags)
General Asterisk PBX channel definitions.
#define TEXT_SIZE
Maximum text message length.
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
#define AST_PTHREADT_NULL
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
void ast_config_destroy(struct ast_config *config)
Destroys a config.
#define NUM_SAMPLES
The number of samples to configure the portaudio stream for.
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
#define CV_STRFIELD(__x, __obj, __field)
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 struct console_pvt globals
static struct ao2_container * pvts
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
static void store_config_core(struct console_pvt *pvt, const char *var, const char *value)
Store a configuration parameter in a pvt struct.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
#define OUTPUT_CHANNELS
Mono Output.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
const ast_string_field language
static void * stream_monitor(void *data)
Stream monitor thread.
static int init_pvt(struct console_pvt *pvt, const char *name)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define ao2_unlink(container, obj)
static char * cli_console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
answer command from the console
#define CV_BOOL(__x, __dst)
helper macros to assign the value to a BOOL, UINT, static string and dynamic string ...
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
#define ao2_iterator_next(iter)
#define ao2_alloc(data_size, destructor_fn)
struct ast_format_cap * capabilities
static void set_active(struct console_pvt *pvt, const char *value)
static int load_module(void)
Load the module.
#define ast_channel_unlock(chan)
static int console_write(struct ast_channel *chan, struct ast_frame *f)
static ast_rwlock_t active_lock
static int console_text(struct ast_channel *c, const char *text)
static struct console_pvt * ref_pvt(struct console_pvt *pvt)
const ast_string_field input_device
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
#define INPUT_CHANNELS
Mono Input.
Module has failed to load, may be in an inconsistent state.
#define V_BEGIN
Dance, Kirby, Dance!
#define ao2_find(container, arg, flags)
unsigned int flags
Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags.
Structure used to handle boolean flags.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
Configures a jitterbuffer on a channel.
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)
#define ast_rwlock_wrlock(a)
static void destroy_pvts(void)
struct ast_frame ast_null_frame
static struct console_pvt * active_pvt
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
const char * ast_channel_name(const struct ast_channel *chan)
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
static int pvt_cmp_cb(void *obj, void *arg, int flags)
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
const ast_string_field mohinterpret
static char * cli_list_devices(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 struct console_pvt * get_active_pvt(void)
union ast_frame::@263 data
const ast_string_field output_device
enum ast_frame_type frametype
#define console_pvt_lock(pvt)
lock a console_pvt struct
static int console_answer(struct ast_channel *c)
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
static struct console_pvt * find_pvt(const char *name)
const ast_string_field name
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
General jitterbuffer configuration.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
static int stop_stream(struct console_pvt *pvt)
#define AST_MUTEX_DEFINE_STATIC(mutex)
const ast_string_field cid_name
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
const ast_string_field exten
static const char config_file[]
#define ast_mutex_unlock(a)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ao2_link(container, obj)
static void pvt_destructor(void *obj)