50 #include <sys/ioctl.h> 53 #include <linux/soundcard.h> 54 #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__) || defined(__GLIBC__) || defined(__sun) 55 #include <sys/soundcard.h> 57 #include <soundcard.h> 80 .resync_threshold = 1000,
214 #define FRAME_SIZE 160 215 #define QUEUE_SIZE 10 217 #if defined(__FreeBSD__) 220 #define FRAGS ( ( (6 * 5) << 16 ) | 0x6 ) 227 #define TEXT_SIZE 256 232 #define O_CLOSE 0x444 234 #if defined( __OpenBSD__ ) || defined( __NetBSD__ ) 235 #define DEV_DSP "/dev/audio" 237 #define DEV_DSP "/dev/dsp" 272 #define WARN_used_blocks 1 284 #define BOOST_SCALE (1<<9) 334 .lastopen = { 0, 0 },
342 const char *
data,
int *cause);
353 static char tdesc[] =
"OSS Console Channel Driver";
358 .description =
tdesc,
383 for (o = oss_default.
next; o && o->
name && dev && strcmp(o->
name, dev) != 0; o = o->
next);
411 if (src && *src !=
'\0')
419 *ctx = strrchr(*ext,
'@');
432 struct audio_buf_info info;
434 if (ioctl(o->
sounddev, SNDCTL_DSP_GETOSPACE, &info)) {
444 ast_log(
LOG_WARNING,
"fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
483 int fmt, desired, res, fd;
486 ioctl(o->
sounddev, SNDCTL_DSP_RESET, 0);
504 #if __BYTE_ORDER == __LITTLE_ENDIAN 509 res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
516 res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
518 res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
519 if (res == 0 && (fmt & DSP_CAP_DUPLEX)) {
520 ast_verb(2,
"Console is full duplex\n");
535 res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
541 res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
547 if (fmt != desired) {
550 "Requested %d Hz, got %d Hz -- sound may be choppy\n",
561 res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
565 "Unable to set fragment size -- sound may be choppy\n");
571 res = PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT;
572 res = ioctl(fd, SNDCTL_DSP_SETTRIGGER, &res);
588 ast_verbose(
" << Console Received digit %c of duration %u ms >> \n",
596 ast_verbose(
" << Console Received text %s >> \n", text);
615 ast_verbose(
" << Call to device '%s' dnid '%s' rdnis '%s' on console from '%s' <%s> >>\n",
634 ast_verbose(
"<< Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
648 ast_verbose(
" << Console call has been answered >> \n");
686 while (src < f->datalen) {
713 memset(f,
'\0',
sizeof(
struct ast_frame));
740 for (i = 0; i < f->
samples; i++) {
781 ast_verbose(
" << Console Has Been Placed on Hold >> \n");
785 ast_verbose(
" << Console Has Been Retrieved from Hold >> \n");
803 c =
ast_channel_alloc(1, state, o->
cid_num, o->
cid_name,
"", ext, ctx, assignedids, requestor, 0,
"Console/%s", o->
device + 5);
822 ast_channel_language_set(c, o->
language);
900 " Generic handler for console commands.\n";
921 if (!strcasecmp(var,
"device")) {
933 e->
command =
"console {set|show} autoanswer [on|off]";
935 "Usage: console {set|show} autoanswer [on|off]\n" 936 " Enables or disables autoanswer feature. If used without\n" 937 " argument, displays the current on/off status of autoanswer.\n" 938 " The default value of autoanswer is in 'oss.conf'.\n";
956 if (!strcasecmp(a->
argv[e->
args-1],
"on"))
958 else if (!strcasecmp(a->
argv[e->
args - 1],
"off"))
972 ast_cli(fd,
"No one is calling us\n");
989 "Usage: console answer\n" 990 " Answers an incoming call on the console (OSS) channel.\n";
1013 e->
command =
"console send text";
1015 "Usage: console send text <message>\n" 1016 " Sends a text message for display on the remote terminal.\n";
1030 int i = strlen(buf);
1046 e->
command =
"console hangup";
1048 "Usage: console hangup\n" 1049 " Hangs up any call currently placed on the console.\n";
1075 "Usage: console flash\n" 1076 " Flashes the call currently placed on the console.\n";
1102 "Usage: console dial [extension[@context]]\n" 1103 " Dials a given extension (and context if specified)\n";
1116 ast_cli(a->
fd,
"Already in a call. You can only dial digits until you hangup.\n");
1121 for (i = 0; i < strlen(digits); i++) {
1139 ast_cli(a->
fd,
"No such extension '%s' in context '%s'\n", mye, myc);
1152 e->
command =
"console {mute|unmute} [toggle]";
1154 "Usage: console {mute|unmute} [toggle]\n" 1155 " Mute/unmute the microphone.\n";
1163 if (strcasecmp(a->
argv[e->
args-1],
"toggle"))
1168 if (!strcasecmp(s,
"mute"))
1170 else if (!strcasecmp(s,
"unmute"))
1174 ast_cli(a->
fd,
"Console mic is %s\n", o->
mute ?
"off" :
"on");
1185 e->
command =
"console transfer";
1187 "Usage: console transfer <extension>[@context]\n" 1188 " Transfers the currently connected call to the given extension (and\n" 1189 " context if specified)\n";
1200 ast_cli(a->
fd,
"There is no call to transfer\n");
1219 e->
command =
"console {set|show} active [<device>]";
1221 "Usage: console active [device]\n" 1222 " If used without a parameter, displays which device is the current\n" 1223 " console. If a device is specified, the console sound device is changed to\n" 1224 " the device specified.\n";
1232 else if (a->
argc != 4)
1236 if (strcmp(a->
argv[3],
"show") == 0) {
1237 for (o = oss_default.
next; o; o = o->
next)
1256 if (sscanf(s,
"%30lf", &boost) != 1) {
1280 "Usage: console boost [boost in dB]\n" 1281 " Sets or display mic boost in dB\n";
1289 else if (a->
argc == 3)
1317 for (i = 0; i < strlen(s); i++) {
1318 if (!isalnum(s[i]) && strchr(
" \t-/", s[i]) ==
NULL) {
1381 if (strcmp(ctg,
"general") == 0) {
1403 if (system(cmd) < 0) {
1414 if (o == &oss_default)
1420 ast_verb(1,
"Device %s not detected\n", ctg);
1421 ast_verb(1,
"Turn off OSS support by adding " "'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
1425 ast_log(
LOG_WARNING,
"XXX I don't work right with non " "full-duplex sound cards XXX\n");
1429 if (o != &oss_default) {
1431 oss_default.
next = o;
1437 if (o != &oss_default)
1450 o = oss_default.
next;
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
struct ast_variable * next
struct chan_oss_pvt * next
static void store_mixer(struct chan_oss_pvt *o, const char *s)
enum chan_oss_pvt::@127 duplex
Main Channel structure associated with a channel.
struct ast_party_dialed::@246 number
Dialed/Called number.
char ctx[AST_MAX_CONTEXT]
#define AST_CLI_DEFINE(fn, txt,...)
static char * console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
char * str
Subscriber phone number (Malloced)
Asterisk main include file. File version handling, generic pbx functions.
char * str
Subscriber phone number (Malloced)
int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen)
static int unload_module(void)
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)
#define DEFAULT_SAMPLE_RATE
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)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
static char * console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
answer command from the console
static struct ast_channel_tech oss_tech
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
#define CV_UINT(__x, __dst)
#define CONSOLE_VIDEO_CMDS
static int oss_digit_begin(struct ast_channel *c, char digit)
descriptor for a cli entry.
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
static char * console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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 int oss_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen)
Structure for variables, used for configurations and for channel variables.
static char * console_do_answer(int fd)
helper function for the answer key/cli command
Structure to pass both assignedid values to channel drivers.
ast_channel_state
ast_channel states
static char * ast_ext_ctx(const char *src, char **ext, char **ctx)
void console_video_start(struct video_desc *env, struct ast_channel *owner)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
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 ...
#define ast_str_alloca(init_len)
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
void ast_verbose(const char *fmt,...)
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
char oss_write_buf[FRAME_SIZE *2]
#define CV_END
close a variable parsing block
void ast_cli(int fd, const char *fmt,...)
#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.
static int oss_answer(struct ast_channel *c)
remote side answered the phone
#define ast_verb(level,...)
#define CV_STR(__x, __dst)
int console_write_video(struct ast_channel *chan, struct ast_frame *f)
struct ast_frame_subclass subclass
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
int args
This gets set in ast_cli_register()
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_strlen_zero(foo)
static int oss_digit_end(struct ast_channel *c, char digit, unsigned int duration)
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
int console_video_config(struct video_desc **penv, const char *var, const char *val)
#define CV_F(__pattern, __body)
call a generic function if the name matches.
#define ast_config_load(filename, flags)
Load a config file.
enum ast_transfer_result ast_bridge_transfer_blind(int is_external, struct ast_channel *transferer, const char *exten, const char *context, transfer_channel_cb new_channel_cb, void *user_data)
Blind transfer target to the extension and context provided.
struct ast_party_id ani
Automatic Number Identification (ANI)
General Asterisk PBX channel definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
#define AST_MAX_EXTENSION
#define AST_CAUSE_NORMAL_CLEARING
static int setformat(struct chan_oss_pvt *o, int mode)
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...
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
#define ast_strdupa(s)
duplicate a string in memory from the stack
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 struct ast_channel * oss_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)
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
static char * console_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
descriptor for one of our channels.
static struct chan_oss_pvt * find_desc(const char *dev)
returns a pointer to the descriptor with the given name
static struct ast_cli_entry cli_oss[]
AST_MODULE_INFO_STANDARD_DEPRECATED(ASTERISK_GPL_KEY, "OSS Console Channel Driver")
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
static char * console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Console send text CLI command.
#define CV_BOOL(__x, __dst)
helper macros to assign the value to a BOOL, UINT, static string and dynamic string ...
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
static int oss_write(struct ast_channel *chan, struct ast_frame *f)
used for data coming from the network
struct ast_format_cap * capabilities
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
static char * console_active(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * console_boost(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int used_blocks(struct chan_oss_pvt *o)
Returns the number of blocks used in the audio output channel.
#define ast_channel_unlock(chan)
static void parse(struct mgcp_request *req)
static int oss_hangup(struct ast_channel *c)
#define ast_calloc(num, len)
A wrapper for calloc()
static int oss_text(struct ast_channel *c, const char *text)
static void store_callerid(struct chan_oss_pvt *o, const char *s)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
char ext[AST_MAX_EXTENSION]
Module has failed to load, may be in an inconsistent state.
struct ast_channel * owner
static int oss_call(struct ast_channel *c, const char *dest, int timeout)
handler for incoming calls. Either autoanswer, or start ringing
unsigned int flags
Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags.
int console_video_cli(struct video_desc *env, const char *var, int fd)
Structure used to handle boolean flags.
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
static struct ast_frame * oss_read(struct ast_channel *chan)
void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
Configures a jitterbuffer on a channel.
static void store_boost(struct chan_oss_pvt *o, const char *s)
store the boost factor
char mohinterpret[MAX_MUSICCLASS]
void console_video_uninit(struct video_desc *env)
static int load_module(void)
Load the module.
Standard Command Line Interface.
static char * console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int get_gui_startup(struct video_desc *env)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#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 char * console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
static char * console_transfer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct ast_channel * oss_new(struct chan_oss_pvt *o, char *ext, char *ctx, int state, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
allocate a new channel.
const char * ast_channel_context(const struct ast_channel *chan)
int error(const char *format,...)
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_format * format
static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value)
static struct ast_jb_conf default_jbconf
char oss_read_buf[FRAME_SIZE *2+AST_FRIENDLY_OFFSET]
#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.
char language[MAX_LANGUAGE]
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
unsigned char valid
TRUE if the number information is valid/present.
struct video_desc * get_video_desc(struct ast_channel *c)
return the pointer to the video descriptor
General jitterbuffer configuration.
static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
static char * console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int soundcard_writeframe(struct chan_oss_pvt *o, short *data)
static struct ast_jb_conf global_jbconf
static struct chan_oss_pvt oss_default
static struct chan_oss_pvt * store_config(struct ast_config *cfg, char *ctg)
#define AST_APP_ARG(name)
Define an application argument.
struct ast_party_number number
Subscriber phone number.
#define ast_module_ref(mod)
Hold a reference to the module.