[zaptel-commits] mattf: branch 1.4 r4296 - /branches/1.4/ztmonitor.c
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Thu May 15 10:09:39 CDT 2008
Author: mattf
Date: Thu May 15 10:09:38 2008
New Revision: 4296
URL: http://svn.digium.com/view/zaptel?view=rev&rev=4296
Log:
Add support for stereo output of receive and transmit streams in ztmonitor
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=4296&r1=4295&r2=4296
==============================================================================
--- branches/1.4/ztmonitor.c (original)
+++ branches/1.4/ztmonitor.c Thu May 15 10:09:38 2008
@@ -38,6 +38,7 @@
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
+#include <ctype.h>
#ifdef STANDALONE_ZAPATA
#include "kernel/zaptel.h"
#include "tonezone.h"
@@ -50,10 +51,12 @@
/*
* 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 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 MON_STEREO 4 /*!< stereo mix of rx/tx streams */
+#define MON_PRE_STEREO 5 /*!< stereo mix of rx/tx before echo can. This is exactly what is fed into the echo can */
#define BLOCK_SIZE 240
@@ -65,7 +68,7 @@
* the main loop in case we ever add a signal
* handler.
*/
-static FILE* ofh[4] = {0, 0, 0, 0};
+static FILE* ofh[6] = {0, 0, 0, 0, 0, 0};
static int stereo = 0;
static int verbose = 0;
@@ -269,29 +272,36 @@
int pfd[4] = {-1, -1, -1, -1};
short buf_brx[BLOCK_SIZE * 2];
short buf_tx[BLOCK_SIZE * 4];
+ short stereobuf[BLOCK_SIZE * 4];
int res_brx, res_tx;
int visual = 0;
int multichannel = 0;
int ossoutput = 0;
int preecho = 0;
int savefile = 0;
+ int stereo_output = 0;
+ int limit = 0;
+ int readcount = 0;
int x, i, chan;
struct zt_confinfo zc;
if ((argc < 2) || (atoi(argv[1]) < 1)) {
- fprintf(stderr, "Usage: ztmonitor <channel num> [-v[v]] [-m] [-o] [-p] [-f FILE | -r FILE1 -t FILE2] [-F FILE | -R FILE1 -T FILE2]\n");
+ fprintf(stderr, "Usage: ztmonitor <channel num> [-v[v]] [-m] [-o] [-p] [-l limit] [-f FILE | -s FILE | -r FILE1 -t FILE2] [-F FILE | -S FILE | -R FILE1 -T FILE2]\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -v: Visual mode. Implies -m.\n");
fprintf(stderr, " -vv: Visual/Verbose mode. Implies -m.\n");
+ fprintf(stderr, " -l LIMIT: Stop after reading LIMIT bytes\n");
fprintf(stderr, " -m: Separate rx/tx streams.\n");
fprintf(stderr, " -o: Output audio via OSS. Note: Only 'normal' combined rx/tx streams are output via OSS.\n");
fprintf(stderr, " -p: Get a pre-echocanceled stream.\n");
fprintf(stderr, " -f FILE: Save combined rx/tx stream to FILE. Cannot be used with -m.\n");
fprintf(stderr, " -r FILE: Save rx stream to FILE. Implies -m.\n");
fprintf(stderr, " -t FILE: Save tx stream to FILE. Implies -m.\n");
+ fprintf(stderr, " -s FILE: Save stereo rx/tx stream to FILE.\n");
fprintf(stderr, " -F FILE: Save combined pre-echocanceled rx/tx stream to FILE. Cannot be used with -m. Implies -p.\n");
fprintf(stderr, " -R FILE: Save pre-echocanceled rx stream to FILE. Implies -m and -p.\n");
fprintf(stderr, " -T FILE: Save pre-echocanceled tx stream to FILE. Implies -m and -p.\n");
+ fprintf(stderr, " -S FILE: Save pre-echocanceled stereo rx/tx stream to FILE. Implies -p.\n");
fprintf(stderr, "Examples:\n");
fprintf(stderr, "Save a stream to a file\n");
fprintf(stderr, " ztmonitor 1 -f stream.raw\n");
@@ -319,7 +329,8 @@
verbose = 1;
multichannel = 1;
} else if ((!strcmp(argv[i], "-f") || !strcmp(argv[i], "-r") || !strcmp(argv[i], "-t")
- || !strcmp(argv[i], "-F") || !strcmp(argv[i], "-R") || !strcmp(argv[i], "-T"))
+ || !strcmp(argv[i], "-F") || !strcmp(argv[i], "-R") || !strcmp(argv[i], "-T")
+ || !strcmp(argv[i], "-s") || !strcmp(argv[i], "-S"))
&& (i+1) < argc) {
char *output_file;
@@ -335,6 +346,11 @@
savefile = 1;
multichannel = 1;
x = MON_TX;
+ } else if (!strcmp(argv[i], "-s")) {
+ savefile = 1;
+ stereo_output = 1;
+ multichannel = 1;
+ x = MON_STEREO;
} else if (!strcmp(argv[i], "-F")) {
savefile = 1;
preecho = 1;
@@ -349,6 +365,12 @@
multichannel = 1;
preecho = 1;
x = MON_PRE_TX;
+ } else if (!strcmp(argv[i], "-S")) {
+ savefile = 1;
+ preecho = 1;
+ stereo_output = 1;
+ multichannel = 1;
+ x = MON_PRE_STEREO;
} else
x = MON_BRX;
@@ -368,6 +390,9 @@
ossoutput = 1;
} else if (!strcmp(argv[i], "-p")) {
preecho = 1;
+ } else if (!strcmp(argv[i], "-l") && isdigit(argv[i+1][0])) {
+ limit = atoi(argv[i+1]);
+ i++;
}
}
@@ -469,6 +494,7 @@
res_brx = read(pfd[MON_BRX], buf_brx, sizeof(buf_brx));
if (res_brx < 1)
break;
+ readcount += res_brx;
if (ofh[MON_BRX])
fwrite(buf_brx, 1, res_brx, ofh[MON_BRX]);
@@ -479,6 +505,14 @@
if (ofh[MON_TX])
fwrite(buf_tx, 1, res_tx, ofh[MON_TX]);
+ if (stereo_output && ofh[MON_STEREO]) {
+ for (x=0;x<res_tx;x++) {
+ stereobuf[x*2] = buf_brx[x];
+ stereobuf[x*2+1] = buf_tx[x];
+ }
+ fwrite(stereobuf, 1, res_tx*2, ofh[MON_STEREO]);
+ }
+
if (visual) {
if (res_brx == res_tx)
visualize((short *)buf_tx, (short *)buf_brx, res_brx/2);
@@ -500,6 +534,14 @@
break;
if (ofh[MON_PRE_TX])
fwrite(buf_tx, 1, res_tx, ofh[MON_PRE_TX]);
+
+ if (stereo_output && ofh[MON_PRE_STEREO]) {
+ for (x=0;x<res_brx;x++) {
+ stereobuf[x*2] = buf_brx[x];
+ stereobuf[x*2+1] = buf_tx[x];
+ }
+ fwrite(stereobuf, 1, res_brx*2, ofh[MON_PRE_STEREO]);
+ }
/* XXX How are we going to visualize the preecho set of streams?
if (visual) {
@@ -519,10 +561,17 @@
} else
write(afd, buf_brx, res_brx);
}
+
+ if (limit && readcount >= limit) {
+ /* bail if we've read too much */
+ break;
+ }
}
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]);
+ if (ofh[MON_STEREO]) fclose(ofh[MON_STEREO]);
+ if (ofh[MON_PRE_STEREO]) fclose(ofh[MON_PRE_STEREO]);
exit(0);
}
More information about the zaptel-commits
mailing list