[zaptel-commits] qwell: branch 1.4 r3742 - /branches/1.4/ztmonitor.c
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Fri Jan 25 18:09:45 CST 2008
Author: qwell
Date: Fri Jan 25 18:09:45 2008
New Revision: 3742
URL: http://svn.digium.com/view/zaptel?view=rev&rev=3742
Log:
Swap RX and TX streams in ztmonitor, as the files were being saved incorrectly.
Add several defines, and modify many "magic numbers" to use them correctly (see above)
Fix error message in audio_open()
(closes issue #11194)
Reported by: meneault
Patches:
ztmonitor-c_patch_txrx_1_4_rev3121 uploaded by meneault (license 260)
ztmonitor-c_patch_buffer_1_4_rev3121 uploaded by meneault (license 260)
ztmonitor-c_patch_audio_1_4_rev3121 uploaded by meneault (license 260)
Modified:
branches/1.4/ztmonitor.c
Modified: branches/1.4/ztmonitor.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/ztmonitor.c?view=diff&rev=3742&r1=3741&r2=3742
==============================================================================
--- branches/1.4/ztmonitor.c (original)
+++ branches/1.4/ztmonitor.c Fri Jan 25 18:09:45 2008
@@ -47,6 +47,16 @@
#endif
#include <linux/soundcard.h>
+/*
+* defines for file handle numbers
+*/
+#define MON_BRX 0 /*!< both channels if multichannel==1 or receive otherwise */
+#define MON_TX 1 /*!< transmit channel */
+#define MON_PRE_BRX 2 /*!< same as MON_BRX but before echo cancellation */
+#define MON_PRE_TX 3 /*!< same as MON_TX but before echo cancellation */
+
+#define BLOCK_SIZE 240
+
#define BUFFERS 4
#define FRAG_SIZE 8
@@ -96,8 +106,8 @@
if (speed != 8000)
fprintf(stderr, "Warning: Requested 8000 Hz, got %d\n", speed);
if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fragsize)) {
- fprintf(stderr, "Sound card won't let me set fragment size to 10 64-byte buffers (%x)\n"
- "so sound may be choppy: %s.\n", fragsize, strerror(errno));
+ fprintf(stderr, "Sound card won't let me set fragment size to %u %u-byte buffers (%x)\n"
+ "so sound may be choppy: %s.\n", BUFFERS, (1 << FRAG_SIZE), fragsize, strerror(errno));
}
bzero(&ispace, sizeof(ispace));
bzero(&ospace, sizeof(ospace));
@@ -131,7 +141,7 @@
close(fd);
return -1;
}
- x = 240;
+ x = BLOCK_SIZE;
if (ioctl(fd, ZT_SET_BLOCKSIZE, &x)) {
fprintf(stderr, "unable to set sane block size: %s\n", strerror(errno));
close(fd);
@@ -257,15 +267,15 @@
{
int afd = -1;
int pfd[4] = {-1, -1, -1, -1};
- short buf[8192];
- short buf2[16384];
- int res, res2;
+ short buf_brx[BLOCK_SIZE * 2];
+ short buf_tx[BLOCK_SIZE * 4];
+ int res_brx, res_tx;
int visual = 0;
int multichannel = 0;
int ossoutput = 0;
int preecho = 0;
int savefile = 0;
- int x, i;
+ int x, i, chan;
struct zt_confinfo zc;
if ((argc < 2) || (atoi(argv[1]) < 1)) {
@@ -295,6 +305,9 @@
fprintf(stderr, " ztmonitor 1 -m -p -r streamrx.raw -t streamtx.raw -R streampreechorx.raw -T streampreechotx.raw\n");
exit(1);
}
+
+ chan = atoi(argv[1]);
+
for (i = 2; i < argc; ++i) {
if (!strcmp(argv[i], "-v")) {
if (visual)
@@ -313,31 +326,31 @@
/* Set which file descriptor to use */
if (!strcmp(argv[i], "-f")) {
savefile = 1;
- x = 0;
+ x = MON_BRX;
} else if (!strcmp(argv[i], "-r")) {
savefile = 1;
multichannel = 1;
- x = 0;
+ x = MON_BRX;
} else if (!strcmp(argv[i], "-t")) {
savefile = 1;
multichannel = 1;
- x = 1;
+ x = MON_TX;
} else if (!strcmp(argv[i], "-F")) {
savefile = 1;
preecho = 1;
- x = 2;
+ x = MON_PRE_BRX;
} else if (!strcmp(argv[i], "-R")) {
savefile = 1;
multichannel = 1;
preecho = 1;
- x = 2;
+ x = MON_PRE_BRX;
} else if (!strcmp(argv[i], "-T")) {
savefile = 1;
multichannel = 1;
preecho = 1;
- x = 3;
+ x = MON_PRE_TX;
} else
- x = 0;
+ x = MON_BRX;
++i; /* we care about the file name */
output_file = argv[i];
@@ -376,50 +389,50 @@
}
/* Open Pseudo device */
- if ((pfd[0] = pseudo_open()) < 0)
+ if ((pfd[MON_BRX] = pseudo_open()) < 0)
exit(1);
- if (multichannel && ((pfd[1] = pseudo_open()) < 0))
+ if (multichannel && ((pfd[MON_TX] = pseudo_open()) < 0))
exit(1);
if (preecho) {
- if ((pfd[2] = pseudo_open()) < 0)
+ if ((pfd[MON_PRE_BRX] = pseudo_open()) < 0)
exit(1);
- if (multichannel && ((pfd[3] = pseudo_open()) < 0))
+ if (multichannel && ((pfd[MON_PRE_TX] = pseudo_open()) < 0))
exit(1);
}
/* Conference them */
if (multichannel) {
memset(&zc, 0, sizeof(zc));
zc.chan = 0;
- zc.confno = atoi(argv[1]);
+ zc.confno = chan;
/* Two pseudo's, one for tx, one for rx */
- zc.confmode = ZT_CONF_MONITORTX;
- if (ioctl(pfd[0], ZT_SETCONF, &zc) < 0) {
+ zc.confmode = ZT_CONF_MONITOR;
+ if (ioctl(pfd[MON_BRX], ZT_SETCONF, &zc) < 0) {
fprintf(stderr, "Unable to monitor: %s\n", strerror(errno));
exit(1);
}
memset(&zc, 0, sizeof(zc));
zc.chan = 0;
- zc.confno = atoi(argv[1]);
- zc.confmode = ZT_CONF_MONITOR;
- if (ioctl(pfd[1], ZT_SETCONF, &zc) < 0) {
+ zc.confno = chan;
+ zc.confmode = ZT_CONF_MONITORTX;
+ if (ioctl(pfd[MON_TX], ZT_SETCONF, &zc) < 0) {
fprintf(stderr, "Unable to monitor: %s\n", strerror(errno));
exit(1);
}
if (preecho) {
memset(&zc, 0, sizeof(zc));
zc.chan = 0;
- zc.confno = atoi(argv[1]);
+ zc.confno = chan;
/* Two pseudo's, one for tx, one for rx */
- zc.confmode = ZT_CONF_MONITOR_TX_PREECHO;
- if (ioctl(pfd[2], ZT_SETCONF, &zc) < 0) {
+ zc.confmode = ZT_CONF_MONITOR_RX_PREECHO;
+ if (ioctl(pfd[MON_PRE_BRX], ZT_SETCONF, &zc) < 0) {
fprintf(stderr, "Unable to monitor: %s\n", strerror(errno));
exit(1);
}
memset(&zc, 0, sizeof(zc));
zc.chan = 0;
- zc.confno = atoi(argv[1]);
- zc.confmode = ZT_CONF_MONITOR_RX_PREECHO;
- if (ioctl(pfd[3], ZT_SETCONF, &zc) < 0) {
+ zc.confno = chan;
+ zc.confmode = ZT_CONF_MONITOR_TX_PREECHO;
+ if (ioctl(pfd[MON_PRE_TX], ZT_SETCONF, &zc) < 0) {
fprintf(stderr, "Unable to monitor: %s\n", strerror(errno));
exit(1);
}
@@ -427,18 +440,18 @@
} else {
memset(&zc, 0, sizeof(zc));
zc.chan = 0;
- zc.confno = atoi(argv[1]);
+ zc.confno = chan;
zc.confmode = ZT_CONF_MONITORBOTH;
- if (ioctl(pfd[0], ZT_SETCONF, &zc) < 0) {
+ if (ioctl(pfd[MON_BRX], ZT_SETCONF, &zc) < 0) {
fprintf(stderr, "Unable to monitor: %s\n", strerror(errno));
exit(1);
}
if (preecho) {
memset(&zc, 0, sizeof(zc));
zc.chan = 0;
- zc.confno = atoi(argv[1]);
+ zc.confno = chan;
zc.confmode = ZT_CONF_MONITORBOTH_PREECHO;
- if (ioctl(pfd[2], ZT_SETCONF, &zc) < 0) {
+ if (ioctl(pfd[MON_PRE_BRX], ZT_SETCONF, &zc) < 0) {
fprintf(stderr, "Unable to monitor: %s\n", strerror(errno));
exit(1);
}
@@ -453,40 +466,40 @@
}
/* Now, copy from pseudo to audio */
for (;;) {
- res = read(pfd[0], buf, sizeof(buf));
- if (res < 1)
+ res_brx = read(pfd[MON_BRX], buf_brx, sizeof(buf_brx));
+ if (res_brx < 1)
break;
- if (ofh[0])
- fwrite(buf, 1, res, ofh[0]);
+ if (ofh[MON_BRX])
+ fwrite(buf_brx, 1, res_brx, ofh[MON_BRX]);
if (multichannel) {
- res2 = read(pfd[1], buf2, res);
- if (res2 < 1)
+ res_tx = read(pfd[MON_TX], buf_tx, res_brx);
+ if (res_tx < 1)
break;
- if (ofh[1])
- fwrite(buf2, 1, res2, ofh[1]);
+ if (ofh[MON_TX])
+ fwrite(buf_tx, 1, res_tx, ofh[MON_TX]);
if (visual) {
- if (res == res2)
- visualize((short *)buf, (short *)buf2, res/2);
+ if (res_brx == res_tx)
+ visualize((short *)buf_tx, (short *)buf_brx, res_brx/2);
else
- printf("Huh? res = %d, res2 = %d?\n", res, res2);
+ printf("Huh? res_tx = %d, res_brx = %d?\n", res_tx, res_brx);
}
}
if (preecho) {
- res = read(pfd[2], buf, sizeof(buf));
- if (res < 1)
+ res_brx = read(pfd[MON_PRE_BRX], buf_brx, sizeof(buf_brx));
+ if (res_brx < 1)
break;
- if (ofh[2])
- fwrite(buf, 1, res, ofh[2]);
+ if (ofh[MON_PRE_BRX])
+ fwrite(buf_brx, 1, res_brx, ofh[MON_PRE_BRX]);
if (multichannel) {
- res2 = read(pfd[3], buf2, res);
- if (res2 < 1)
+ res_tx = read(pfd[MON_PRE_TX], buf_tx, res_brx);
+ if (res_tx < 1)
break;
- if (ofh[3])
- fwrite(buf2, 1, res, ofh[3]);
+ if (ofh[MON_PRE_TX])
+ fwrite(buf_tx, 1, res_tx, ofh[MON_PRE_TX]);
/* XXX How are we going to visualize the preecho set of streams?
if (visual) {
@@ -500,16 +513,16 @@
if (ossoutput && afd) {
if (stereo) {
- for (x=0;x<res;x++)
- buf2[x<<1] = buf2[(x<<1) + 1] = buf[x];
- write(afd, buf2, res << 1);
+ for (x=0;x<res_brx;x++)
+ buf_tx[x<<1] = buf_tx[(x<<1) + 1] = buf_brx[x];
+ write(afd, buf_tx, res_brx << 1);
} else
- write(afd, buf, res);
- }
- }
- if (ofh[0]) fclose(ofh[0]);
- if (ofh[1]) fclose(ofh[1]);
- if (ofh[2]) fclose(ofh[2]);
- if (ofh[3]) fclose(ofh[3]);
+ write(afd, buf_brx, res_brx);
+ }
+ }
+ if (ofh[MON_BRX]) fclose(ofh[MON_BRX]);
+ if (ofh[MON_TX]) fclose(ofh[MON_TX]);
+ if (ofh[MON_PRE_BRX]) fclose(ofh[MON_PRE_BRX]);
+ if (ofh[MON_PRE_TX]) fclose(ofh[MON_PRE_TX]);
exit(0);
}
More information about the zaptel-commits
mailing list