summaryrefslogtreecommitdiff
path: root/ztmonitor.c
diff options
context:
space:
mode:
authormattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2008-05-15 15:09:38 +0000
committermattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2008-05-15 15:09:38 +0000
commit8214a17dc5da2b587c0502f10e5d5b0d8e57fbc3 (patch)
treeed5c05bf8715f685b46da469d8d7c22cc0d8c0dc /ztmonitor.c
parent39d606d3ce05016ac4f78b6dfe604ade277ae77e (diff)
Add support for stereo output of receive and transmit streams in ztmonitor (from Switchvox)
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@4296 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'ztmonitor.c')
-rw-r--r--ztmonitor.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/ztmonitor.c b/ztmonitor.c
index 29fc721..3c8b5ff 100644
--- a/ztmonitor.c
+++ b/ztmonitor.c
@@ -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 main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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);
@@ -501,6 +535,14 @@ int main(int argc, char *argv[])
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) {
if (res == res2)
@@ -519,10 +561,17 @@ int main(int argc, char *argv[])
} 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);
}