diff options
author | markster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2002-04-11 03:21:33 +0000 |
---|---|---|
committer | markster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2002-04-11 03:21:33 +0000 |
commit | 88de18b1201bda0720d0a5f35749dd81c15b2994 (patch) | |
tree | a3811a3434d3ee3a4f1551317a5f5fbf19f673dd /ztmonitor.c | |
parent | e6dd22f41fe22e02fc2ac5898995e3e760f9f7ad (diff) |
Version 0.2.0 from FTP
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@73 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'ztmonitor.c')
-rwxr-xr-x | ztmonitor.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/ztmonitor.c b/ztmonitor.c new file mode 100755 index 0000000..d10f47e --- /dev/null +++ b/ztmonitor.c @@ -0,0 +1,140 @@ +/* + * Monitor a Zaptel Channel + * + * Written by Mark Spencer <markster@linux-support.net> + * Based on previous works, designs, and architectures conceived and + * written by Jim Dixon <jim@lambdatel.com>. + * + * Copyright (C) 2001 Jim Dixon / Zapata Telephony. + * Copyright (C) 2001 Linux Support Services, Inc. + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under thet erms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Primary Author: Mark Spencer <markster@linux-support.net> + * + */ + +#include <stdio.h> +#include <getopt.h> +#include <string.h> +#include <stdarg.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <errno.h> +#ifdef STANDALONE_ZAPATA +#include "zaptel.h" +#include "tonezone.h" +#else +#include <linux/zaptel.h> +#include <tonezone.h> +#endif +#include <linux/soundcard.h> + +int audio_open(void) +{ + int fd; + int speed = 8000; + int fmt = AFMT_S16_LE; + int stereo = 0; + fd = open("/dev/dsp", O_WRONLY); + if (fd < 0) { + fprintf(stderr, "Unable to open /dev/dsp: %s\n", strerror(errno)); + return -1; + } + /* Step 1: Signed linear */ + if (ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) < 0) { + fprintf(stderr, "ioctl(SETFMT) failed: %s\n", strerror(errno)); + close(fd); + return -1; + } + /* Step 2: Make non-stereo */ + if (ioctl(fd, SNDCTL_DSP_STEREO, &stereo) < 0) { + fprintf(stderr, "ioctl(STEREO) failed: %s\n", strerror(errno)); + close(fd); + return -1; + } + /* Step 3: Make 8000 Hz */ + if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) < 0) { + fprintf(stderr, "ioctl(SPEED) failed: %s\n", strerror(errno)); + close(fd); + return -1; + } + if (speed != 8000) + fprintf(stderr, "Warning: Requested 8000 Hz, got %d\n", speed); + return fd; +} + +int pseudo_open(void) +{ + int fd; + int x = 1; + fd = open("/dev/zap/pseudo", O_RDWR); + if (fd < 0) { + fprintf(stderr, "Unable to open pseudo channel: %s\n", strerror(errno)); + return -1; + } + if (ioctl(fd, ZT_SETLINEAR, &x)) { + fprintf(stderr, "Unable to set linear mode: %s\n", strerror(errno)); + close(fd); + return -1; + } + x = 240; + if (ioctl(fd, ZT_SET_BLOCKSIZE, &x)) { + fprintf(stderr, "unable to set sane block size: %s\n", strerror(errno)); + close(fd); + return -1; + } + return fd; +} + +int main(int argc, char *argv[]) +{ + int afd, pfd; + char buf[8192]; + int res; + struct zt_confinfo zc; + + if ((argc < 2) || (atoi(argv[1]) < 1)) { + fprintf(stderr, "Usage: ztmonitor <channel num>\n"); + exit(1); + } + /* Open audio */ + if ((afd = audio_open()) < 0) + exit(1); + /* Open Pseudo device */ + if ((pfd = pseudo_open()) < 0) + exit(1); + /* Conference them */ + memset(&zc, 0, sizeof(zc)); + zc.chan = 0; + zc.confno = atoi(argv[1]); + zc.confmode = ZT_CONF_MONITORBOTH; + if (ioctl(pfd, ZT_SETCONF, &zc) < 0) { + fprintf(stderr, "Unable to monitor: %s\n", strerror(errno)); + exit(1); + } + /* Now, copy from pseudo to audio */ + for (;;) { + res = read(pfd, buf, sizeof(buf)); + if (res < 1) + break; + write(afd, buf, res); + } + exit(0); +} |