2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2007, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * FreeBSD changes and multiple device support by Luigi Rizzo, 2005.05.25
9 * note-this code best seen with ts=8 (8-spaces tabs) in the editor
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
17 * This program is free software, distributed under the terms of
18 * the GNU General Public License Version 2. See the LICENSE file
19 * at the top of the source tree.
22 // #define HAVE_VIDEO_CONSOLE // uncomment to enable video
25 * \brief Channel driver for OSS sound cards
27 * \author Mark Spencer <markster@digium.com>
31 * \arg \ref Config_oss
33 * \ingroup channel_drivers
37 <depend>ossaudio</depend>
42 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
44 #include <ctype.h> /* isalnum() used here */
46 #include <sys/ioctl.h>
49 #include <linux/soundcard.h>
50 #elif defined(__FreeBSD__) || defined(__CYGWIN__)
51 #include <sys/soundcard.h>
53 #include <soundcard.h>
56 #include "asterisk/channel.h"
57 #include "asterisk/file.h"
58 #include "asterisk/callerid.h"
59 #include "asterisk/module.h"
60 #include "asterisk/pbx.h"
61 #include "asterisk/cli.h"
62 #include "asterisk/causes.h"
63 #include "asterisk/musiconhold.h"
64 #include "asterisk/app.h"
66 #include "console_video.h"
68 /* ringtones we use */
74 /*! Global jitterbuffer configuration - by default, jb is disabled */
75 static struct ast_jb_conf default_jbconf =
79 .resync_threshold = -1,
82 static struct ast_jb_conf global_jbconf;
85 * Basic mode of operation:
87 * we have one keyboard (which receives commands from the keyboard)
88 * and multiple headset's connected to audio cards.
89 * Cards/Headsets are named as the sections of oss.conf.
90 * The section called [general] contains the default parameters.
92 * At any time, the keyboard is attached to one card, and you
93 * can switch among them using the command 'console foo'
94 * where 'foo' is the name of the card you want.
96 * oss.conf parameters are
100 ; General config options, with default values shown.
101 ; You should use one section per device, with [general] being used
102 ; for the first device and also as a template for other devices.
104 ; All but 'debug' can go also in the device-specific sections.
106 ; debug = 0x0 ; misc debug flags, default is 0
108 ; Set the device to use for I/O
111 ; Optional mixer command to run upon startup (e.g. to set
112 ; volume levels, mutes, etc.
115 ; Software mic volume booster (or attenuator), useful for sound
116 ; cards or microphones with poor sensitivity. The volume level
117 ; is in dB, ranging from -20.0 to +20.0
118 ; boost = n ; mic volume boost in dB
120 ; Set the callerid for outgoing calls
121 ; callerid = John Doe <555-1234>
123 ; autoanswer = no ; no autoanswer on call
124 ; autohangup = yes ; hangup when other party closes
125 ; extension = s ; default extension to call
126 ; context = default ; default context for outgoing calls
127 ; language = "" ; default language
129 ; Default Music on Hold class to use when this channel is placed on hold in
130 ; the case that the music class is not set on the channel with
131 ; Set(CHANNEL(musicclass)=whatever) in the dialplan and the peer channel
132 ; putting this one on hold did not suggest a class to use.
134 ; mohinterpret=default
136 ; If you set overridecontext to 'yes', then the whole dial string
137 ; will be interpreted as an extension, which is extremely useful
138 ; to dial SIP, IAX and other extensions which use the '@' character.
139 ; The default is 'no' just for backward compatibility, but the
140 ; suggestion is to change it.
141 ; overridecontext = no ; if 'no', the last @ will start the context
142 ; if 'yes' the whole string is an extension.
144 ; low level device parameters in case you have problems with the
145 ; device driver on your operating system. You should not touch these
146 ; unless you know what you are doing.
147 ; queuesize = 10 ; frames in device driver
148 ; frags = 8 ; argument to SETFRAGMENT
150 ;------------------------------ JITTER BUFFER CONFIGURATION --------------------------
151 ; jbenable = yes ; Enables the use of a jitterbuffer on the receiving side of an
152 ; OSS channel. Defaults to "no". An enabled jitterbuffer will
153 ; be used only if the sending side can create and the receiving
154 ; side can not accept jitter. The OSS channel can't accept jitter,
155 ; thus an enabled jitterbuffer on the receive OSS side will always
156 ; be used if the sending side can create jitter.
158 ; jbmaxsize = 200 ; Max length of the jitterbuffer in milliseconds.
160 ; jbresyncthreshold = 1000 ; Jump in the frame timestamps over which the jitterbuffer is
161 ; resynchronized. Useful to improve the quality of the voice, with
162 ; big jumps in/broken timestamps, usualy sent from exotic devices
163 ; and programs. Defaults to 1000.
165 ; jbimpl = fixed ; Jitterbuffer implementation, used on the receiving side of an OSS
166 ; channel. Two implementations are currenlty available - "fixed"
167 ; (with size always equals to jbmax-size) and "adaptive" (with
168 ; variable size, actually the new jb of IAX2). Defaults to fixed.
170 ; jblog = no ; Enables jitterbuffer frame logging. Defaults to "no".
171 ;-----------------------------------------------------------------------------------
174 ; device = /dev/dsp1 ; alternate device
178 .. and so on for the other cards.
183 * The following parameters are used in the driver:
185 * FRAME_SIZE the size of an audio frame, in samples.
186 * 160 is used almost universally, so you should not change it.
188 * FRAGS the argument for the SETFRAGMENT ioctl.
189 * Overridden by the 'frags' parameter in oss.conf
191 * Bits 0-7 are the base-2 log of the device's block size,
192 * bits 16-31 are the number of blocks in the driver's queue.
193 * There are a lot of differences in the way this parameter
194 * is supported by different drivers, so you may need to
195 * experiment a bit with the value.
196 * A good default for linux is 30 blocks of 64 bytes, which
197 * results in 6 frames of 320 bytes (160 samples).
198 * FreeBSD works decently with blocks of 256 or 512 bytes,
199 * leaving the number unspecified.
200 * Note that this only refers to the device buffer size,
201 * this module will then try to keep the lenght of audio
202 * buffered within small constraints.
204 * QUEUE_SIZE The max number of blocks actually allowed in the device
205 * driver's buffer, irrespective of the available number.
206 * Overridden by the 'queuesize' parameter in oss.conf
208 * Should be >=2, and at most as large as the hw queue above
209 * (otherwise it will never be full).
212 #define FRAME_SIZE 160
213 #define QUEUE_SIZE 10
215 #if defined(__FreeBSD__)
218 #define FRAGS ( ( (6 * 5) << 16 ) | 0x6 )
222 * XXX text message sizes are probably 256 chars, but i am
223 * not sure if there is a suitable definition anywhere.
225 #define TEXT_SIZE 256
228 #define TRYOPEN 1 /* try to open on startup */
230 #define O_CLOSE 0x444 /* special 'close' mode for device */
231 /* Which device to use */
232 #if defined( __OpenBSD__ ) || defined( __NetBSD__ )
233 #define DEV_DSP "/dev/audio"
235 #define DEV_DSP "/dev/dsp"
239 #define MIN(a,b) ((a) < (b) ? (a) : (b))
242 #define MAX(a,b) ((a) > (b) ? (a) : (b))
245 static char *config = "oss.conf"; /* default config file */
247 static int oss_debug;
250 * Each sound is made of 'datalen' samples of sound, repeated as needed to
251 * generate 'samplen' samples of data, then followed by 'silencelen' samples
252 * of silence. The loop is repeated if 'repeat' is set.
264 static struct sound sounds[] = {
265 { AST_CONTROL_RINGING, "RINGING", ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
266 { AST_CONTROL_BUSY, "BUSY", busy, sizeof(busy)/2, 4000, 4000, 1 },
267 { AST_CONTROL_CONGESTION, "CONGESTION", busy, sizeof(busy)/2, 2000, 2000, 1 },
268 { AST_CONTROL_RING, "RING10", ring10, sizeof(ring10)/2, 16000, 32000, 1 },
269 { AST_CONTROL_ANSWER, "ANSWER", answer, sizeof(answer)/2, 2200, 0, 0 },
270 { -1, NULL, 0, 0, 0, 0 }, /* end marker */
274 * \brief descriptor for one of our channels.
276 * There is one used for 'default' values (from the [general] entry in
277 * the configuration file), and then one instance for each device
278 * (the default is cloned from [general], others are only created
279 * if the relevant section exists).
281 struct chan_oss_pvt {
282 struct chan_oss_pvt *next;
286 * cursound indicates which in struct sound we play. -1 means nothing,
287 * any other value is a valid sound, in which case sampsent indicates
288 * the next sample to send in [0..samplen + silencelen]
289 * nosound is set to disable the audio data from the channel
290 * (so we can play the tones etc.).
292 int sndcmd[2]; /*!< Sound command pipe */
293 int cursound; /*!< index of sound to send */
294 int sampsent; /*!< # of sound samples sent */
295 int nosound; /*!< set to block audio from the PBX */
297 int total_blocks; /*!< total blocks in the output device */
299 enum { M_UNSET, M_FULL, M_READ, M_WRITE } duplex;
303 char *mixer_cmd; /*!< initial command to issue to the mixer */
304 unsigned int queuesize; /*!< max fragments in queue */
305 unsigned int frags; /*!< parameter for SETFRAGMENT */
307 int warned; /*!< various flags used for warnings */
308 #define WARN_used_blocks 1
311 int w_errors; /*!< overfull in the write path */
312 struct timeval lastopen;
317 /*! boost support. BOOST_SCALE * 10 ^(BOOST_MAX/20) must
318 * be representable in 16 bits to avoid overflows.
320 #define BOOST_SCALE (1<<9)
321 #define BOOST_MAX 40 /*!< slightly less than 7 bits */
322 int boost; /*!< input boost, scaled by BOOST_SCALE */
323 char device[64]; /*!< device to open */
327 struct ast_channel *owner;
329 struct video_desc *env; /*!< parameters for video support */
331 char ext[AST_MAX_EXTENSION];
332 char ctx[AST_MAX_CONTEXT];
333 char language[MAX_LANGUAGE];
334 char cid_name[256]; /*XXX */
335 char cid_num[256]; /*XXX */
336 char mohinterpret[MAX_MUSICCLASS];
338 /*! buffers used in oss_write */
339 char oss_write_buf[FRAME_SIZE * 2];
341 /*! buffers used in oss_read - AST_FRIENDLY_OFFSET space for headers
342 * plus enough room for a full frame
344 char oss_read_buf[FRAME_SIZE * 2 + AST_FRIENDLY_OFFSET];
345 int readpos; /*!< read position above */
346 struct ast_frame read_f; /*!< returned by oss_read */
349 /*! forward declaration */
350 static struct chan_oss_pvt *find_desc(char *dev);
352 /*! \brief return the pointer to the video descriptor */
353 struct video_desc *get_video_desc(struct ast_channel *c)
355 struct chan_oss_pvt *o = c->tech_pvt;
356 return o ? o->env : NULL;
358 static struct chan_oss_pvt oss_default = {
361 .duplex = M_UNSET, /* XXX check this */
364 .queuesize = QUEUE_SIZE,
368 .readpos = AST_FRIENDLY_OFFSET, /* start here on reads */
369 .lastopen = { 0, 0 },
370 .boost = BOOST_SCALE,
373 static char *oss_active; /*!< the active device */
375 static int setformat(struct chan_oss_pvt *o, int mode);
377 static struct ast_channel *oss_request(const char *type, int format, void *data
379 static int oss_digit_begin(struct ast_channel *c, char digit);
380 static int oss_digit_end(struct ast_channel *c, char digit, unsigned int duration);
381 static int oss_text(struct ast_channel *c, const char *text);
382 static int oss_hangup(struct ast_channel *c);
383 static int oss_answer(struct ast_channel *c);
384 static struct ast_frame *oss_read(struct ast_channel *chan);
385 static int oss_call(struct ast_channel *c, char *dest, int timeout);
386 static int oss_write(struct ast_channel *chan, struct ast_frame *f);
387 static int oss_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen);
388 static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
389 static char tdesc[] = "OSS Console Channel Driver";
391 /* cannot do const because need to update some fields at runtime */
392 static struct ast_channel_tech oss_tech = {
394 .description = tdesc,
395 .capabilities = AST_FORMAT_SLINEAR, /* overwritten later */
396 .requester = oss_request,
397 .send_digit_begin = oss_digit_begin,
398 .send_digit_end = oss_digit_end,
399 .send_text = oss_text,
400 .hangup = oss_hangup,
401 .answer = oss_answer,
405 .write_video = console_write_video,
406 .indicate = oss_indicate,
411 * \brief returns a pointer to the descriptor with the given name
413 static struct chan_oss_pvt *find_desc(char *dev)
415 struct chan_oss_pvt *o = NULL;
418 ast_log(LOG_WARNING, "null dev\n");
420 for (o = oss_default.next; o && o->name && dev && strcmp(o->name, dev) != 0; o = o->next);
423 ast_log(LOG_WARNING, "could not find <%s>\n", dev ? dev : "--no-device--");
429 * \brief split a string in extension-context, returns pointers to malloc'ed
432 * If we do not have 'overridecontext' then the last @ is considered as
433 * a context separator, and the context is overridden.
434 * This is usually not very necessary as you can play with the dialplan,
435 * and it is nice not to need it because you have '@' in SIP addresses.
437 * \return the buffer address.
439 static char *ast_ext_ctx(const char *src, char **ext, char **ctx)
441 struct chan_oss_pvt *o = find_desc(oss_active);
443 if (ext == NULL || ctx == NULL)
444 return NULL; /* error */
448 if (src && *src != '\0')
449 *ext = ast_strdup(src);
454 if (!o->overridecontext) {
455 /* parse from the right */
456 *ctx = strrchr(*ext, '@');
465 * \brief Returns the number of blocks used in the audio output channel
467 static int used_blocks(struct chan_oss_pvt *o)
469 struct audio_buf_info info;
471 if (ioctl(o->sounddev, SNDCTL_DSP_GETOSPACE, &info)) {
472 if (!(o->warned & WARN_used_blocks)) {
473 ast_log(LOG_WARNING, "Error reading output space\n");
474 o->warned |= WARN_used_blocks;
479 if (o->total_blocks == 0) {
480 if (0) /* debugging */
481 ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
482 o->total_blocks = info.fragments;
485 return o->total_blocks - info.fragments;
488 /*! Write an exactly FRAME_SIZE sized frame */
489 static int soundcard_writeframe(struct chan_oss_pvt *o, short *data)
494 setformat(o, O_RDWR);
496 return 0; /* not fatal */
498 * Nothing complex to manage the audio device queue.
499 * If the buffer is full just drop the extra, otherwise write.
500 * XXX in some cases it might be useful to write anyways after
501 * a number of failures, to restart the output chain.
503 res = used_blocks(o);
504 if (res > o->queuesize) { /* no room to write a block */
505 if (o->w_errors++ == 0 && (oss_debug & 0x4))
506 ast_log(LOG_WARNING, "write: used %d blocks (%d)\n", res, o->w_errors);
510 return write(o->sounddev, (void *)data, FRAME_SIZE * 2);
514 * \brief Handler for 'sound writable' events from the sound thread.
516 * Builds a frame from the high level description of the sounds,
517 * and passes it to the audio device.
518 * The actual sound is made of 1 or more sequences of sound samples
519 * (s->datalen, repeated to make s->samplen samples) followed by
520 * s->silencelen samples of silence. The position in the sequence is stored
521 * in o->sampsent, which goes between 0 .. s->samplen+s->silencelen.
522 * In case we fail to write a frame, don't update o->sampsent.
524 static void send_sound(struct chan_oss_pvt *o)
526 short myframe[FRAME_SIZE];
528 int l_sampsent = o->sampsent;
531 if (o->cursound < 0) /* no sound to send */
534 s = &sounds[o->cursound];
536 for (ofs = 0; ofs < FRAME_SIZE; ofs += l) {
537 l = s->samplen - l_sampsent; /* # of available samples */
539 start = l_sampsent % s->datalen; /* source offset */
540 l = MIN(l, FRAME_SIZE - ofs); /* don't overflow the frame */
541 l = MIN(l, s->datalen - start); /* don't overflow the source */
542 bcopy(s->data + start, myframe + ofs, l * 2);
544 ast_log(LOG_WARNING, "send_sound sound %d/%d of %d into %d\n", l_sampsent, l, s->samplen, ofs);
546 } else { /* end of samples, maybe some silence */
547 static const short silence[FRAME_SIZE] = { 0, };
551 l = MIN(l, FRAME_SIZE - ofs);
552 bcopy(silence, myframe + ofs, l * 2);
554 } else { /* silence is over, restart sound if loop */
555 if (s->repeat == 0) { /* last block */
557 o->nosound = 0; /* allow audio data */
558 if (ofs < FRAME_SIZE) /* pad with silence */
559 bcopy(silence, myframe + ofs, (FRAME_SIZE - ofs) * 2);
565 l = soundcard_writeframe(o, myframe);
567 o->sampsent = l_sampsent; /* update status */
570 static void *sound_thread(void *arg)
573 struct chan_oss_pvt *o = (struct chan_oss_pvt *) arg;
576 * Just in case, kick the driver by trying to read from it.
577 * Ignore errors - this read is almost guaranteed to fail.
579 read(o->sounddev, ign, sizeof(ign));
583 struct timeval *to = NULL, t;
587 FD_SET(o->sndcmd[0], &rfds);
588 maxfd = o->sndcmd[0]; /* pipe from the main process */
589 if (o->cursound > -1 && o->sounddev < 0)
590 setformat(o, O_RDWR); /* need the channel, try to reopen */
591 else if (o->cursound == -1 && o->owner == NULL)
592 setformat(o, O_CLOSE); /* can close */
593 if (o->sounddev > -1) {
594 if (!o->owner) { /* no one owns the audio, so we must drain it */
595 FD_SET(o->sounddev, &rfds);
596 maxfd = MAX(o->sounddev, maxfd);
598 if (o->cursound > -1) {
600 * We would like to use select here, but the device
601 * is always writable, so this would become busy wait.
602 * So we rather set a timeout to 1/2 of the frame size.
605 t.tv_usec = (1000000 * FRAME_SIZE) / (5 * DEFAULT_SAMPLE_RATE);
609 /* ast_select emulates linux behaviour in terms of timeout handling */
610 res = ast_select(maxfd + 1, &rfds, &wfds, NULL, to);
612 ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
616 if (FD_ISSET(o->sndcmd[0], &rfds)) {
617 /* read which sound to play from the pipe */
620 read(o->sndcmd[0], &what, sizeof(what));
621 for (i = 0; sounds[i].ind != -1; i++) {
622 if (sounds[i].ind == what) {
625 o->nosound = 1; /* block audio from pbx */
629 if (sounds[i].ind == -1)
630 ast_log(LOG_WARNING, "invalid sound index: %d\n", what);
632 if (o->sounddev > -1) {
633 if (FD_ISSET(o->sounddev, &rfds)) /* read and ignore errors */
634 read(o->sounddev, ign, sizeof(ign));
635 if (to != NULL) /* maybe it is possible to write */
639 return NULL; /* Never reached */
643 * reset and close the device if opened,
644 * then open and initialize it in the desired mode,
645 * trigger reads and writes so we can start using it.
647 static int setformat(struct chan_oss_pvt *o, int mode)
649 int fmt, desired, res, fd;
651 if (o->sounddev >= 0) {
652 ioctl(o->sounddev, SNDCTL_DSP_RESET, 0);
657 if (mode == O_CLOSE) /* we are done */
659 if (ast_tvdiff_ms(ast_tvnow(), o->lastopen) < 1000)
660 return -1; /* don't open too often */
661 o->lastopen = ast_tvnow();
662 fd = o->sounddev = open(o->device, mode | O_NONBLOCK);
664 ast_log(LOG_WARNING, "Unable to re-open DSP device %s: %s\n", o->device, strerror(errno));
668 ast_channel_set_fd(o->owner, 0, fd);
670 #if __BYTE_ORDER == __LITTLE_ENDIAN
675 res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
677 ast_log(LOG_WARNING, "Unable to set format to 16-bit signed\n");
682 res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
683 /* Check to see if duplex set (FreeBSD Bug) */
684 res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
685 if (res == 0 && (fmt & DSP_CAP_DUPLEX)) {
686 ast_verb(2, "Console is full duplex\n");
701 res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
703 ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
706 fmt = desired = DEFAULT_SAMPLE_RATE; /* 8000 Hz desired */
707 res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
710 ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
713 if (fmt != desired) {
714 if (!(o->warned & WARN_speed)) {
716 "Requested %d Hz, got %d Hz -- sound may be choppy\n",
718 o->warned |= WARN_speed;
722 * on Freebsd, SETFRAGMENT does not work very well on some cards.
723 * Default to use 256 bytes, let the user override
727 res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
729 if (!(o->warned & WARN_frag)) {
731 "Unable to set fragment size -- sound may be choppy\n");
732 o->warned |= WARN_frag;
736 /* on some cards, we need SNDCTL_DSP_SETTRIGGER to start outputting */
737 res = PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT;
738 res = ioctl(fd, SNDCTL_DSP_SETTRIGGER, &res);
739 /* it may fail if we are in half duplex, never mind */
744 * some of the standard methods supported by channels.
746 static int oss_digit_begin(struct ast_channel *c, char digit)
751 static int oss_digit_end(struct ast_channel *c, char digit, unsigned int duration)
753 /* no better use for received digits than print them */
754 ast_verbose(" << Console Received digit %c of duration %u ms >> \n",
759 static int oss_text(struct ast_channel *c, const char *text)
761 /* print received messages */
762 ast_verbose(" << Console Received text %s >> \n", text);
766 /*! \brief Play ringtone 'x' on device 'o' */
767 static void ring(struct chan_oss_pvt *o, int x)
769 write(o->sndcmd[1], &x, sizeof(x));
774 * \brief handler for incoming calls. Either autoanswer, or start ringing
776 static int oss_call(struct ast_channel *c, char *dest, int timeout)
778 struct chan_oss_pvt *o = c->tech_pvt;
779 struct ast_frame f = { 0, };
780 AST_DECLARE_APP_ARGS(args,
784 char *parse = ast_strdupa(dest);
786 AST_NONSTANDARD_APP_ARGS(args, parse, '/');
788 ast_verbose(" << Call to device '%s' dnid '%s' rdnis '%s' on console from '%s' <%s> >>\n", dest, c->cid.cid_dnid, c->cid.cid_rdnis, c->cid.cid_name, c->cid.cid_num);
789 if (!ast_strlen_zero(args.flags) && strcasecmp(args.flags, "answer") == 0) {
790 f.frametype = AST_FRAME_CONTROL;
791 f.subclass = AST_CONTROL_ANSWER;
792 ast_queue_frame(c, &f);
793 } else if (!ast_strlen_zero(args.flags) && strcasecmp(args.flags, "noanswer") == 0) {
794 f.frametype = AST_FRAME_CONTROL;
795 f.subclass = AST_CONTROL_RINGING;
796 ast_queue_frame(c, &f);
797 ring(o, AST_CONTROL_RING);
798 } else if (o->autoanswer) {
799 ast_verbose(" << Auto-answered >> \n");
800 f.frametype = AST_FRAME_CONTROL;
801 f.subclass = AST_CONTROL_ANSWER;
802 ast_queue_frame(c, &f);
804 ast_verbose("<< Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
805 f.frametype = AST_FRAME_CONTROL;
806 f.subclass = AST_CONTROL_RINGING;
807 ast_queue_frame(c, &f);
808 ring(o, AST_CONTROL_RING);
814 * \brief remote side answered the phone
816 static int oss_answer(struct ast_channel *c)
818 struct chan_oss_pvt *o = c->tech_pvt;
820 ast_verbose(" << Console call has been answered >> \n");
822 /* play an answer tone (XXX do we really need it ?) */
823 ring(o, AST_CONTROL_ANSWER);
825 ast_setstate(c, AST_STATE_UP);
831 static int oss_hangup(struct ast_channel *c)
833 struct chan_oss_pvt *o = c->tech_pvt;
839 ast_verbose(" << Hangup on console >> \n");
840 console_video_uninit(o->env);
841 ast_module_unref(ast_module_info->self);
843 if (o->autoanswer || o->autohangup) {
844 /* Assume auto-hangup too */
846 setformat(o, O_CLOSE);
848 /* Make congestion noise */
849 ring(o, AST_CONTROL_CONGESTION);
855 /*! \brief used for data coming from the network */
856 static int oss_write(struct ast_channel *c, struct ast_frame *f)
859 struct chan_oss_pvt *o = c->tech_pvt;
861 /* Immediately return if no sound is enabled */
864 /* Stop any currently playing sound */
867 * we could receive a block which is not a multiple of our
868 * FRAME_SIZE, so buffer it locally and write to the device
869 * in FRAME_SIZE chunks.
870 * Keep the residue stored for future use.
872 src = 0; /* read position into f->data */
873 while (src < f->datalen) {
874 /* Compute spare room in the buffer */
875 int l = sizeof(o->oss_write_buf) - o->oss_write_dst;
877 if (f->datalen - src >= l) { /* enough to fill a frame */
878 memcpy(o->oss_write_buf + o->oss_write_dst, f->data + src, l);
879 soundcard_writeframe(o, (short *) o->oss_write_buf);
881 o->oss_write_dst = 0;
882 } else { /* copy residue */
883 l = f->datalen - src;
884 memcpy(o->oss_write_buf + o->oss_write_dst, f->data + src, l);
885 src += l; /* but really, we are done */
886 o->oss_write_dst += l;
892 static struct ast_frame *oss_read(struct ast_channel *c)
895 struct chan_oss_pvt *o = c->tech_pvt;
896 struct ast_frame *f = &o->read_f;
898 /* XXX can be simplified returning &ast_null_frame */
899 /* prepare a NULL frame in case we don't have enough data to return */
900 bzero(f, sizeof(struct ast_frame));
901 f->frametype = AST_FRAME_NULL;
902 f->src = oss_tech.type;
904 res = read(o->sounddev, o->oss_read_buf + o->readpos, sizeof(o->oss_read_buf) - o->readpos);
905 if (res < 0) /* audio data not ready, return a NULL frame */
909 if (o->readpos < sizeof(o->oss_read_buf)) /* not enough samples */
915 o->readpos = AST_FRIENDLY_OFFSET; /* reset read pointer for next frame */
916 if (c->_state != AST_STATE_UP) /* drop data if frame is not up */
918 /* ok we can build and deliver the frame to the caller */
919 f->frametype = AST_FRAME_VOICE;
920 f->subclass = AST_FORMAT_SLINEAR;
921 f->samples = FRAME_SIZE;
922 f->datalen = FRAME_SIZE * 2;
923 f->data = o->oss_read_buf + AST_FRIENDLY_OFFSET;
924 if (o->boost != BOOST_SCALE) { /* scale and clip values */
926 int16_t *p = (int16_t *) f->data;
927 for (i = 0; i < f->samples; i++) {
928 x = (p[i] * o->boost) / BOOST_SCALE;
937 f->offset = AST_FRIENDLY_OFFSET;
941 static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
943 struct chan_oss_pvt *o = newchan->tech_pvt;
948 static int oss_indicate(struct ast_channel *c, int cond, const void *data, size_t datalen)
950 struct chan_oss_pvt *o = c->tech_pvt;
954 case AST_CONTROL_BUSY:
955 case AST_CONTROL_CONGESTION:
956 case AST_CONTROL_RINGING:
962 o->nosound = 0; /* when cursound is -1 nosound must be 0 */
965 case AST_CONTROL_VIDUPDATE:
969 case AST_CONTROL_HOLD:
970 ast_verbose(" << Console Has Been Placed on Hold >> \n");
971 ast_moh_start(c, data, o->mohinterpret);
974 case AST_CONTROL_UNHOLD:
975 ast_verbose(" << Console Has Been Retrieved from Hold >> \n");
980 ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, c->name);
991 * \brief allocate a new channel.
993 static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx, int state)
995 struct ast_channel *c;
997 c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, 0, "OSS/%s", o->device + 5);
1000 c->tech = &oss_tech;
1001 if (o->sounddev < 0)
1002 setformat(o, O_RDWR);
1003 ast_channel_set_fd(c, 0, o->sounddev); /* -1 if device closed, override later */
1004 c->nativeformats = AST_FORMAT_SLINEAR;
1005 /* if the console makes the call, add video to the offer */
1006 if (state == AST_STATE_RINGING)
1007 c->nativeformats |= console_video_formats;
1009 c->readformat = AST_FORMAT_SLINEAR;
1010 c->writeformat = AST_FORMAT_SLINEAR;
1013 if (!ast_strlen_zero(o->language))
1014 ast_string_field_set(c, language, o->language);
1015 /* Don't use ast_set_callerid() here because it will
1016 * generate a needless NewCallerID event */
1017 c->cid.cid_ani = ast_strdup(o->cid_num);
1018 if (!ast_strlen_zero(ext))
1019 c->cid.cid_dnid = ast_strdup(ext);
1022 ast_module_ref(ast_module_info->self);
1023 ast_jb_configure(c, &global_jbconf);
1024 if (state != AST_STATE_DOWN) {
1025 if (ast_pbx_start(c)) {
1026 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", c->name);
1028 o->owner = c = NULL;
1029 /* XXX what about the channel itself ? */
1032 console_video_start(get_video_desc(c), c); /* XXX cleanup */
1037 static struct ast_channel *oss_request(const char *type, int format, void *data, int *cause)
1039 struct ast_channel *c;
1040 struct chan_oss_pvt *o;
1041 AST_DECLARE_APP_ARGS(args,
1045 char *parse = ast_strdupa(data);
1047 AST_NONSTANDARD_APP_ARGS(args, parse, '/');
1048 o = find_desc(args.name);
1050 ast_log(LOG_WARNING, "oss_request ty <%s> data 0x%p <%s>\n", type, data, (char *) data);
1052 ast_log(LOG_NOTICE, "Device %s not found\n", args.name);
1053 /* XXX we could default to 'dsp' perhaps ? */
1056 if ((format & AST_FORMAT_SLINEAR) == 0) {
1057 ast_log(LOG_NOTICE, "Format 0x%x unsupported\n", format);
1061 ast_log(LOG_NOTICE, "Already have a call (chan %p) on the OSS channel\n", o->owner);
1062 *cause = AST_CAUSE_BUSY;
1065 c = oss_new(o, NULL, NULL, AST_STATE_DOWN);
1067 ast_log(LOG_WARNING, "Unable to create new OSS channel\n");
1073 static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value);
1075 /*! Generic console command handler. Basically a wrapper for a subset
1076 * of config file options which are also available from the CLI
1078 static char *console_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1080 struct chan_oss_pvt *o = find_desc(oss_active);
1081 const char *var, *value;
1084 e->command = CONSOLE_VIDEO_CMDS;
1085 e->usage = "Usage: " CONSOLE_VIDEO_CMDS "...\n"
1086 " Generic handler for console commands.\n";
1093 if (a->argc < e->args)
1094 return CLI_SHOWUSAGE;
1096 ast_log(LOG_WARNING, "Cannot find device %s (should not happen!)\n",
1100 var = a->argv[e->args-1];
1101 value = a->argc > e->args ? a->argv[e->args] : NULL;
1102 if (value) /* handle setting */
1103 store_config_core(o, var, value);
1104 if (!console_video_cli(o->env, var, a->fd)) /* print video-related values */
1106 /* handle other values */
1107 if (!strcasecmp(var, "device")) {
1108 ast_cli(a->fd, "device is [%s]\n", o->device);
1113 static char *console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1115 struct chan_oss_pvt *o = find_desc(oss_active);
1119 e->command = "console autoanswer [on|off]";
1121 "Usage: console autoanswer [on|off]\n"
1122 " Enables or disables autoanswer feature. If used without\n"
1123 " argument, displays the current on/off status of autoanswer.\n"
1124 " The default value of autoanswer is in 'oss.conf'.\n";
1131 if (a->argc == e->args - 1) {
1132 ast_cli(a->fd, "Auto answer is %s.\n", o->autoanswer ? "on" : "off");
1135 if (a->argc != e->args)
1136 return CLI_SHOWUSAGE;
1138 ast_log(LOG_WARNING, "Cannot find device %s (should not happen!)\n",
1142 if (!strcasecmp(a->argv[e->args-1], "on"))
1144 else if (!strcasecmp(a->argv[e->args - 1], "off"))
1147 return CLI_SHOWUSAGE;
1151 /*! \brief helper function for the answer key/cli command */
1152 char *console_do_answer(int fd);
1153 char *console_do_answer(int fd)
1155 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
1156 struct chan_oss_pvt *o = find_desc(oss_active);
1159 ast_cli(fd, "No one is calling us\n");
1165 ast_queue_frame(o->owner, &f);
1170 * \brief answer command from the console
1172 static char *console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1176 e->command = "console answer";
1178 "Usage: console answer\n"
1179 " Answers an incoming call on the console (OSS) channel.\n";
1183 return NULL; /* no completion */
1185 if (a->argc != e->args)
1186 return CLI_SHOWUSAGE;
1187 return console_do_answer(a->fd);
1191 * \brief Console send text CLI command
1193 * \note concatenate all arguments into a single string. argv is NULL-terminated
1194 * so we can use it right away
1196 static char *console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1198 struct chan_oss_pvt *o = find_desc(oss_active);
1199 char buf[TEXT_SIZE];
1201 if (cmd == CLI_INIT) {
1202 e->command = "console send text";
1204 "Usage: console send text <message>\n"
1205 " Sends a text message for display on the remote terminal.\n";
1207 } else if (cmd == CLI_GENERATE)
1210 if (a->argc < e->args + 1)
1211 return CLI_SHOWUSAGE;
1213 ast_cli(a->fd, "Not in a call\n");
1216 ast_join(buf, sizeof(buf) - 1, a->argv + e->args);
1217 if (!ast_strlen_zero(buf)) {
1218 struct ast_frame f = { 0, };
1219 int i = strlen(buf);
1221 f.frametype = AST_FRAME_TEXT;
1225 ast_queue_frame(o->owner, &f);
1230 static char *console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1232 struct chan_oss_pvt *o = find_desc(oss_active);
1234 if (cmd == CLI_INIT) {
1235 e->command = "console hangup";
1237 "Usage: console hangup\n"
1238 " Hangs up any call currently placed on the console.\n";
1240 } else if (cmd == CLI_GENERATE)
1243 if (a->argc != e->args)
1244 return CLI_SHOWUSAGE;
1247 if (!o->owner && !o->hookstate) { /* XXX maybe only one ? */
1248 ast_cli(a->fd, "No call to hang up\n");
1253 ast_queue_hangup(o->owner);
1254 setformat(o, O_CLOSE);
1258 static char *console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1260 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH };
1261 struct chan_oss_pvt *o = find_desc(oss_active);
1263 if (cmd == CLI_INIT) {
1264 e->command = "console flash";
1266 "Usage: console flash\n"
1267 " Flashes the call currently placed on the console.\n";
1269 } else if (cmd == CLI_GENERATE)
1272 if (a->argc != e->args)
1273 return CLI_SHOWUSAGE;
1275 o->nosound = 0; /* when cursound is -1 nosound must be 0 */
1276 if (!o->owner) { /* XXX maybe !o->hookstate too ? */
1277 ast_cli(a->fd, "No call to flash\n");
1281 if (o->owner) /* XXX must be true, right ? */
1282 ast_queue_frame(o->owner, &f);
1286 static char *console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1288 char *s = NULL, *mye = NULL, *myc = NULL;
1289 struct chan_oss_pvt *o = find_desc(oss_active);
1291 if (cmd == CLI_INIT) {
1292 e->command = "console dial";
1294 "Usage: console dial [extension[@context]]\n"
1295 " Dials a given extension (and context if specified)\n";
1297 } else if (cmd == CLI_GENERATE)
1300 if (a->argc > e->args + 1)
1301 return CLI_SHOWUSAGE;
1302 if (o->owner) { /* already in a call */
1304 struct ast_frame f = { AST_FRAME_DTMF, 0 };
1306 if (a->argc == e->args) { /* argument is mandatory here */
1307 ast_cli(a->fd, "Already in a call. You can only dial digits until you hangup.\n");
1310 s = a->argv[e->args];
1311 /* send the string one char at a time */
1312 for (i = 0; i < strlen(s); i++) {
1314 ast_queue_frame(o->owner, &f);
1318 /* if we have an argument split it into extension and context */
1319 if (a->argc == e->args + 1)
1320 s = ast_ext_ctx(a->argv[e->args], &mye, &myc);
1321 /* supply default values if needed */
1326 if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
1328 oss_new(o, mye, myc, AST_STATE_RINGING);
1330 ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
1336 static char *console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1338 struct chan_oss_pvt *o = find_desc(oss_active);
1341 if (cmd == CLI_INIT) {
1342 e->command = "console {mute|unmute}";
1344 "Usage: console {mute|unmute}\n"
1345 " Mute/unmute the microphone.\n";
1347 } else if (cmd == CLI_GENERATE)
1350 if (a->argc != e->args)
1351 return CLI_SHOWUSAGE;
1352 s = a->argv[e->args-1];
1353 if (!strcasecmp(s, "mute"))
1355 else if (!strcasecmp(s, "unmute"))
1358 return CLI_SHOWUSAGE;
1362 static char *console_transfer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1364 struct chan_oss_pvt *o = find_desc(oss_active);
1365 struct ast_channel *b = NULL;
1366 char *tmp, *ext, *ctx;
1370 e->command = "console transfer";
1372 "Usage: console transfer <extension>[@context]\n"
1373 " Transfers the currently connected call to the given extension (and\n"
1374 " context if specified)\n";
1381 return CLI_SHOWUSAGE;
1384 if (o->owner == NULL || (b = ast_bridged_channel(o->owner)) == NULL) {
1385 ast_cli(a->fd, "There is no call to transfer\n");
1389 tmp = ast_ext_ctx(a->argv[2], &ext, &ctx);
1390 if (ctx == NULL) /* supply default context if needed */
1391 ctx = o->owner->context;
1392 if (!ast_exists_extension(b, ctx, ext, 1, b->cid.cid_num))
1393 ast_cli(a->fd, "No such extension exists\n");
1395 ast_cli(a->fd, "Whee, transferring %s to %s@%s.\n", b->name, ext, ctx);
1396 if (ast_async_goto(b, ctx, ext, 1))
1397 ast_cli(a->fd, "Failed to transfer :(\n");
1404 static char *console_active(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1408 e->command = "console active";
1410 "Usage: console active [device]\n"
1411 " If used without a parameter, displays which device is the current\n"
1412 " console. If a device is specified, the console sound device is changed to\n"
1413 " the device specified.\n";
1420 ast_cli(a->fd, "active console is [%s]\n", oss_active);
1421 else if (a->argc != 3)
1422 return CLI_SHOWUSAGE;
1424 struct chan_oss_pvt *o;
1425 if (strcmp(a->argv[2], "show") == 0) {
1426 for (o = oss_default.next; o; o = o->next)
1427 ast_cli(a->fd, "device [%s] exists\n", o->name);
1430 o = find_desc(a->argv[2]);
1432 ast_cli(a->fd, "No device [%s] exists\n", a->argv[2]);
1434 oss_active = o->name;
1440 * \brief store the boost factor
1442 static void store_boost(struct chan_oss_pvt *o, const char *s)
1445 if (sscanf(s, "%lf", &boost) != 1) {
1446 ast_log(LOG_WARNING, "invalid boost <%s>\n", s);
1449 if (boost < -BOOST_MAX) {
1450 ast_log(LOG_WARNING, "boost %s too small, using %d\n", s, -BOOST_MAX);
1452 } else if (boost > BOOST_MAX) {
1453 ast_log(LOG_WARNING, "boost %s too large, using %d\n", s, BOOST_MAX);
1456 boost = exp(log(10) * boost / 20) * BOOST_SCALE;
1458 ast_log(LOG_WARNING, "setting boost %s to %d\n", s, o->boost);
1461 static char *console_boost(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1463 struct chan_oss_pvt *o = find_desc(oss_active);
1467 e->command = "console boost";
1469 "Usage: console boost [boost in dB]\n"
1470 " Sets or display mic boost in dB\n";
1477 ast_cli(a->fd, "boost currently %5.1f\n", 20 * log10(((double) o->boost / (double) BOOST_SCALE)));
1478 else if (a->argc == 3)
1479 store_boost(o, a->argv[2]);
1483 static struct ast_cli_entry cli_oss[] = {
1484 AST_CLI_DEFINE(console_answer, "Answer an incoming console call"),
1485 AST_CLI_DEFINE(console_hangup, "Hangup a call on the console"),
1486 AST_CLI_DEFINE(console_flash, "Flash a call on the console"),
1487 AST_CLI_DEFINE(console_dial, "Dial an extension on the console"),
1488 AST_CLI_DEFINE(console_mute, "Disable/Enable mic input"),
1489 AST_CLI_DEFINE(console_transfer, "Transfer a call to a different extension"),
1490 AST_CLI_DEFINE(console_cmd, "Generic console command"),
1491 AST_CLI_DEFINE(console_sendtext, "Send text to the remote device"),
1492 AST_CLI_DEFINE(console_autoanswer, "Sets/displays autoanswer"),
1493 AST_CLI_DEFINE(console_boost, "Sets/displays mic boost in dB"),
1494 AST_CLI_DEFINE(console_active, "Sets/displays active console"),
1498 * store the mixer argument from the config file, filtering possibly
1499 * invalid or dangerous values (the string is used as argument for
1500 * system("mixer %s")
1502 static void store_mixer(struct chan_oss_pvt *o, const char *s)
1506 for (i = 0; i < strlen(s); i++) {
1507 if (!isalnum(s[i]) && index(" \t-/", s[i]) == NULL) {
1508 ast_log(LOG_WARNING, "Suspect char %c in mixer cmd, ignoring:\n\t%s\n", s[i], s);
1513 ast_free(o->mixer_cmd);
1514 o->mixer_cmd = ast_strdup(s);
1515 ast_log(LOG_WARNING, "setting mixer %s\n", s);
1519 * store the callerid components
1521 static void store_callerid(struct chan_oss_pvt *o, const char *s)
1523 ast_callerid_split(s, o->cid_name, sizeof(o->cid_name), o->cid_num, sizeof(o->cid_num));
1526 static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value)
1528 CV_START(var, value);
1530 /* handle jb conf */
1531 if (!ast_jb_read_conf(&global_jbconf, (char *)var,(char *) value))
1534 if (!console_video_config(&o->env, var, value))
1535 return; /* matched there */
1536 CV_BOOL("autoanswer", o->autoanswer);
1537 CV_BOOL("autohangup", o->autohangup);
1538 CV_BOOL("overridecontext", o->overridecontext);
1539 CV_STR("device", o->device);
1540 CV_UINT("frags", o->frags);
1541 CV_UINT("debug", oss_debug);
1542 CV_UINT("queuesize", o->queuesize);
1543 CV_STR("context", o->ctx);
1544 CV_STR("language", o->language);
1545 CV_STR("mohinterpret", o->mohinterpret);
1546 CV_STR("extension", o->ext);
1547 CV_F("mixer", store_mixer(o, value));
1548 CV_F("callerid", store_callerid(o, value)) ;
1549 CV_F("boost", store_boost(o, value));
1555 * grab fields from the config file, init the descriptor and open the device.
1557 static struct chan_oss_pvt *store_config(struct ast_config *cfg, char *ctg)
1559 struct ast_variable *v;
1560 struct chan_oss_pvt *o;
1566 if (!(o = ast_calloc(1, sizeof(*o))))
1569 /* "general" is also the default thing */
1570 if (strcmp(ctg, "general") == 0) {
1571 o->name = ast_strdup("dsp");
1572 oss_active = o->name;
1575 o->name = ast_strdup(ctg);
1578 strcpy(o->mohinterpret, "default");
1580 o->lastopen = ast_tvnow(); /* don't leave it 0 or tvdiff may wrap */
1581 /* fill other fields from configuration */
1582 for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
1583 store_config_core(o, v->name, v->value);
1585 if (ast_strlen_zero(o->device))
1586 ast_copy_string(o->device, DEV_DSP, sizeof(o->device));
1590 asprintf(&cmd, "mixer %s", o->mixer_cmd);
1591 ast_log(LOG_WARNING, "running [%s]\n", cmd);
1595 if (o == &oss_default) /* we are done with the default */
1600 if (setformat(o, O_RDWR) < 0) { /* open device */
1601 ast_verb(1, "Device %s not detected\n", ctg);
1602 ast_verb(1, "Turn off OSS support by adding " "'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
1605 if (o->duplex != M_FULL)
1606 ast_log(LOG_WARNING, "XXX I don't work right with non " "full-duplex sound cards XXX\n");
1607 #endif /* TRYOPEN */
1608 if (pipe(o->sndcmd) != 0) {
1609 ast_log(LOG_ERROR, "Unable to create pipe\n");
1612 ast_pthread_create_background(&o->sthread, NULL, sound_thread, o);
1613 /* link into list of devices */
1614 if (o != &oss_default) {
1615 o->next = oss_default.next;
1616 oss_default.next = o;
1621 if (o != &oss_default)
1626 static int load_module(void)
1628 struct ast_config *cfg = NULL;
1630 struct ast_flags config_flags = { 0 };
1632 /* Copy the default jb config over global_jbconf */
1633 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
1635 /* load config file */
1636 if (!(cfg = ast_config_load(config, config_flags))) {
1637 ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
1638 return AST_MODULE_LOAD_DECLINE;
1642 store_config(cfg, ctg);
1643 } while ( (ctg = ast_category_browse(cfg, ctg)) != NULL);
1645 ast_config_destroy(cfg);
1647 if (find_desc(oss_active) == NULL) {
1648 ast_log(LOG_NOTICE, "Device %s not found\n", oss_active);
1649 /* XXX we could default to 'dsp' perhaps ? */
1650 /* XXX should cleanup allocated memory etc. */
1651 return AST_MODULE_LOAD_FAILURE;
1654 oss_tech.capabilities |= console_video_formats;
1656 if (ast_channel_register(&oss_tech)) {
1657 ast_log(LOG_ERROR, "Unable to register channel type 'OSS'\n");
1658 return AST_MODULE_LOAD_FAILURE;
1661 ast_cli_register_multiple(cli_oss, sizeof(cli_oss) / sizeof(struct ast_cli_entry));
1663 return AST_MODULE_LOAD_SUCCESS;
1667 static int unload_module(void)
1669 struct chan_oss_pvt *o;
1671 ast_channel_unregister(&oss_tech);
1672 ast_cli_unregister_multiple(cli_oss, sizeof(cli_oss) / sizeof(struct ast_cli_entry));
1674 for (o = oss_default.next; o; o = o->next) {
1676 if (o->sndcmd[0] > 0) {
1677 close(o->sndcmd[0]);
1678 close(o->sndcmd[1]);
1681 ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
1682 if (o->owner) /* XXX how ??? */
1684 /* XXX what about the thread ? */
1685 /* XXX what about the memory allocated ? */
1690 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "OSS Console Channel Driver");