47 #include <sys/ioctl.h>
50 #include <linux/soundcard.h>
51 #elif defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__GLIBC__) || defined(__sun)
52 #include <sys/soundcard.h>
54 #include <soundcard.h>
75 .resync_threshold = 1000,
209 #define FRAME_SIZE 160
210 #define QUEUE_SIZE 10
212 #if defined(__FreeBSD__)
215 #define FRAGS ( ( (6 * 5) << 16 ) | 0x6 )
222 #define TEXT_SIZE 256
227 #define O_CLOSE 0x444
229 #if defined( __OpenBSD__ ) || defined( __NetBSD__ )
230 #define DEV_DSP "/dev/audio"
232 #define DEV_DSP "/dev/dsp"
262 #define WARN_used_blocks 1
274 #define BOOST_SCALE (1<<9)
312 return o ? o->
env : NULL;
324 .lastopen = { 0, 0 },
332 void *
data,
int *cause);
343 static char tdesc[] =
"OSS Console Channel Driver";
348 .description =
tdesc,
374 for (o = oss_default.
next; o && o->
name && dev && strcmp(o->
name, dev) != 0; o = o->
next);
397 if (ext == NULL || ctx == NULL)
402 if (src && *src !=
'\0')
410 *ctx = strrchr(*ext,
'@');
423 struct audio_buf_info info;
425 if (ioctl(o->
sounddev, SNDCTL_DSP_GETOSPACE, &info)) {
435 ast_log(
LOG_WARNING,
"fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
459 if (o->
w_errors++ == 0 && (oss_debug & 0x4))
474 int fmt, desired, res, fd;
477 ioctl(o->
sounddev, SNDCTL_DSP_RESET, 0);
495 #if __BYTE_ORDER == __LITTLE_ENDIAN
500 res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
507 res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
509 res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
510 if (res == 0 && (fmt & DSP_CAP_DUPLEX)) {
511 ast_verb(2,
"Console is full duplex\n");
526 res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
532 res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
538 if (fmt != desired) {
541 "Requested %d Hz, got %d Hz -- sound may be choppy\n",
552 res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
556 "Unable to set fragment size -- sound may be choppy\n");
562 res = PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT;
563 res = ioctl(fd, SNDCTL_DSP_SETTRIGGER, &res);
579 ast_verbose(
" << Console Received digit %c of duration %u ms >> \n",
587 ast_verbose(
" << Console Received text %s >> \n", text);
606 ast_verbose(
" << Call to device '%s' dnid '%s' rdnis '%s' on console from '%s' <%s> >>\n",
625 ast_verbose(
"<< Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
639 ast_verbose(
" << Console call has been answered >> \n");
677 while (src < f->datalen) {
704 memset(f,
'\0',
sizeof(
struct ast_frame));
730 int16_t *p = (int16_t *) f->
data.
ptr;
771 ast_verbose(
" << Console Has Been Placed on Hold >> \n");
775 ast_verbose(
" << Console Has Been Retrieved from Hold >> \n");
793 c =
ast_channel_alloc(1, state, o->
cid_num, o->
cid_name,
"", ext, ctx, linkedid, 0,
"Console/%s", o->
device + 5);
850 ast_log(
LOG_WARNING,
"oss_request ty <%s> data 0x%p <%s>\n", type, data, (
char *) data);
887 " Generic handler for console commands.\n";
908 if (!strcasecmp(var,
"device")) {
920 e->
command =
"console {set|show} autoanswer [on|off]";
922 "Usage: console {set|show} autoanswer [on|off]\n"
923 " Enables or disables autoanswer feature. If used without\n"
924 " argument, displays the current on/off status of autoanswer.\n"
925 " The default value of autoanswer is in 'oss.conf'.\n";
943 if (!strcasecmp(a->
argv[e->
args-1],
"on"))
945 else if (!strcasecmp(a->
argv[e->
args - 1],
"off"))
959 ast_cli(fd,
"No one is calling us\n");
976 "Usage: console answer\n"
977 " Answers an incoming call on the console (OSS) channel.\n";
1000 e->
command =
"console send text";
1002 "Usage: console send text <message>\n"
1003 " Sends a text message for display on the remote terminal.\n";
1017 int i = strlen(buf);
1033 e->
command =
"console hangup";
1035 "Usage: console hangup\n"
1036 " Hangs up any call currently placed on the console.\n";
1062 "Usage: console flash\n"
1063 " Flashes the call currently placed on the console.\n";
1083 char *mye = NULL, *myc = NULL;
1089 "Usage: console dial [extension[@context]]\n"
1090 " Dials a given extension (and context if specified)\n";
1103 ast_cli(a->
fd,
"Already in a call. You can only dial digits until you hangup.\n");
1108 for (i = 0; i < strlen(s); i++) {
1126 ast_cli(a->
fd,
"No such extension '%s' in context '%s'\n", mye, myc);
1139 e->
command =
"console {mute|unmute} [toggle]";
1141 "Usage: console {mute|unmute} [toggle]\n"
1142 " Mute/unmute the microphone.\n";
1150 if (strcasecmp(a->
argv[e->
args-1],
"toggle"))
1155 if (!strcasecmp(s,
"mute"))
1157 else if (!strcasecmp(s,
"unmute"))
1161 ast_cli(a->
fd,
"Console mic is %s\n", o->
mute ?
"off" :
"on");
1169 char *tmp, *
ext, *ctx;
1173 e->
command =
"console transfer";
1175 "Usage: console transfer <extension>[@context]\n"
1176 " Transfers the currently connected call to the given extension (and\n"
1177 " context if specified)\n";
1188 ast_cli(a->
fd,
"There is no call to transfer\n");
1197 ast_cli(a->
fd,
"No such extension exists\n");
1199 ast_cli(a->
fd,
"Whee, transferring %s to %s@%s.\n", b->
name, ext, ctx);
1201 ast_cli(a->
fd,
"Failed to transfer :(\n");
1212 e->
command =
"console {set|show} active [<device>]";
1214 "Usage: console active [device]\n"
1215 " If used without a parameter, displays which device is the current\n"
1216 " console. If a device is specified, the console sound device is changed to\n"
1217 " the device specified.\n";
1224 ast_cli(a->
fd,
"active console is [%s]\n", oss_active);
1225 else if (a->
argc != 4)
1229 if (strcmp(a->
argv[3],
"show") == 0) {
1230 for (o = oss_default.
next; o; o = o->
next)
1238 oss_active = o->
name;
1249 if (sscanf(s,
"%30lf", &boost) != 1) {
1273 "Usage: console boost [boost in dB]\n"
1274 " Sets or display mic boost in dB\n";
1282 else if (a->
argc == 3)
1310 for (i = 0; i < strlen(s); i++) {
1311 if (!isalnum(s[i]) && strchr(
" \t-/", s[i]) == NULL) {
1374 if (strcmp(ctg,
"general") == 0) {
1376 oss_active = o->
name;
1396 if (system(cmd) < 0) {
1407 if (o == &oss_default)
1413 ast_verb(1,
"Device %s not detected\n", ctg);
1414 ast_verb(1,
"Turn off OSS support by adding " "'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
1418 ast_log(
LOG_WARNING,
"XXX I don't work right with non " "full-duplex sound cards XXX\n");
1422 if (o != &oss_default) {
1424 oss_default.
next = o;
1430 if (o != &oss_default)
1450 ast_log(
LOG_ERROR,
"Config file %s is in an invalid format. Aborting.\n", config);
1487 o = oss_default.
next;
struct chan_oss_pvt * next
union ast_frame_subclass subclass
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
static void store_mixer(struct chan_oss_pvt *o, const char *s)
Main Channel structure associated with a channel.
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)
#define AST_MODULE_INFO_STANDARD(keystr, desc)
enum chan_oss_pvt::@98 duplex
Asterisk main include file. File version handling, generic pbx functions.
char * str
Subscriber phone number (Malloced)
void ast_module_unref(struct ast_module *)
struct ast_party_caller caller
Channel Caller ID information.
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...
#define DEFAULT_SAMPLE_RATE
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
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.
#define CV_STR(__x, __dst)
struct ast_party_name name
Subscriber name.
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
#define CONSOLE_VIDEO_CMDS
char context[AST_MAX_CONTEXT]
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.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
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.
void ast_verbose(const char *fmt,...)
static int oss_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen)
#define CV_UINT(__x, __dst)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
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
struct ast_party_redirecting redirecting
Redirecting/Diversion information.
static char * ast_ext_ctx(const char *src, char **ext, char **ctx)
char * str
Subscriber name (Malloced)
void console_video_start(struct video_desc *env, struct ast_channel *owner)
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 ...
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int console_video_formats
char oss_write_buf[FRAME_SIZE *2]
void ast_cli(int fd, const char *fmt,...)
const ast_string_field linkedid
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,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static int oss_call(struct ast_channel *c, char *dest, int timeout)
handler for incoming calls. Either autoanswer, or start ringing
int console_write_video(struct ast_channel *chan, struct ast_frame *f)
struct ast_channel * ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *name_fmt,...)
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()
static int oss_digit_end(struct ast_channel *c, char digit, unsigned int duration)
int console_video_config(struct video_desc **penv, const char *var, const char *val)
struct ast_party_id id
Caller party ID.
#define ast_asprintf(a, b, c...)
#define CV_END
close a variable parsing block
struct ast_party_id ani
Automatic Number Identification (ANI)
General Asterisk PBX channel definitions.
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
struct ast_party_dialed::@155 number
Dialed/Called number.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define ast_config_load(filename, flags)
Load a config file.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define AST_MAX_EXTENSION
#define AST_CAUSE_NORMAL_CLEARING
static int setformat(struct chan_oss_pvt *o, int mode)
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
#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.
static char language[MAX_LANGUAGE]
static struct ast_channel * oss_new(struct chan_oss_pvt *o, char *ext, char *ctx, int state, const char *linkedid)
allocate a new channel.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
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
struct ast_party_dialed dialed
Dialed/Called information.
#define ast_strdupa(s)
duplicate a string in memory from the stack
static struct ast_cli_entry cli_oss[]
#define CV_BOOL(__x, __dst)
helper macros to assign the value to a BOOL, UINT, static string and dynamic string ...
static char * console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Console send text CLI command.
enum ast_channel_state _state
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
const ast_string_field name
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_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int oss_write(struct ast_channel *chan, struct ast_frame *f)
used for data coming from the network
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.
static void parse(struct mgcp_request *req)
static int oss_hangup(struct ast_channel *c)
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_join(char *s, size_t len, const char *const w[])
char ext[AST_MAX_EXTENSION]
struct ast_channel * owner
unsigned int flags
Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags.
if(yyss+yystacksize-1<=yyssp)
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)
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
#define CV_F(__pattern, __body)
call a generic function if the name matches.
char mohinterpret[MAX_MUSICCLASS]
void console_video_uninit(struct video_desc *env)
static int load_module(void)
#define AST_FORMAT_SLINEAR
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...
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Set the channel to next execute the specified dialplan location.
static char * console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
char * ast_getformatname_multiple(char *buf, size_t size, format_t format)
Get the names of a set of formats.
Data structure associated with a single frame of data.
static struct ast_channel * oss_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
Internal Asterisk hangup causes.
static char * console_transfer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define AST_APP_ARG(name)
Define an application argument.
enum ast_frame_type frametype
struct ast_variable * next
unsigned char valid
TRUE if the name information is valid/present.
#define CONFIG_STATUS_FILEINVALID
static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value)
static struct ast_jb_conf default_jbconf
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
char oss_read_buf[FRAME_SIZE *2+AST_FRIENDLY_OFFSET]
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static snd_pcm_format_t format
union ast_frame::@172 data
struct ast_channel_tech * tech
char language[MAX_LANGUAGE]
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
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
static struct chan_oss_pvt oss_default
static struct chan_oss_pvt * store_config(struct ast_config *cfg, char *ctg)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
struct ast_module * ast_module_ref(struct ast_module *)
struct ast_party_number number
Subscriber phone number.