[linux-dvb] [PATCH] dvbtraffic tweaks

Joe Orton joe at manyfish.co.uk
Mon Jul 4 22:32:59 CEST 2005


Patch below adds -a and -d support to dvbtraffic and a little more error 
handling.

BTW - there are quite a few files in dvb-apps which are missing 
copyright and licensing notices.  Any chance these could be added as 
appropriate?  Is everything supposed to be GPL?

$ grep -L Copyright */*.c
av7110_loadkeys/av7110_loadkeys.c
dvbtraffic/dvbtraffic.c
lib/lnb.c
scan/diseqc.c
scan/dump-vdr.c
scan/dump-zap.c
scan/scan.c
scan/section.c
szap/azap.c
szap/czap.c
szap/tzap.c
ttusb_dec_reset/ttusb_dec_reset.c

Index: dvbtraffic.c
===================================================================
RCS file: /cvs/linuxtv/dvb-apps/util/dvbtraffic/dvbtraffic.c,v
retrieving revision 1.2
diff -u -r1.2 dvbtraffic.c
--- dvbtraffic.c	22 Feb 2005 16:36:32 -0000	1.2
+++ dvbtraffic.c	4 Jul 2005 20:28:18 -0000
@@ -9,29 +9,73 @@
 #include <sys/poll.h>
 #include <sys/time.h>
 #include <string.h>
+#include <limits.h>
 
 #include <linux/dvb/dmx.h>
 
 #define BSIZE 188
 
-int pidt[0x2001];
+static int pidt[0x2001];
+
+static void usage(FILE *output)
+{
+	fprintf(output,
+		"Usage: dvbtraffic [OPTION]...\n"
+		"Options:\n"
+		"	-a N	use DVB /dev/dvb/adapterN/\n"
+		"	-d N	use DVB /dev/dvb/adapter?/demuxN\n"
+		"	-h	display this help\n");
+}
 
 int main(int argc, char **argv)
 {
-	int fd, ffd, packets = 0;
+	char demux_devname[PATH_MAX], dvr_devname[PATH_MAX];
 	struct timeval startt;
 	struct dmx_pes_filter_params flt;
-	char *search;
-	unsigned char buffer[BSIZE];
+	int adapter = 0, demux = 0;
+	char *search = NULL;
+	int fd, ffd, packets = 0;
+	int opt;
+
+	while ((opt = getopt(argc, argv, "a:d:hs:")) != -1) {
+		switch (opt) {
+		case 'a':
+			adapter = atoi(optarg);
+			break;
+		case 'd':
+			demux = atoi(optarg);
+			break;
+		case 'h':
+			usage(stdout);
+			exit(0);
+		case 's':
+			search = strdup(optarg);
+			break;
+		default:
+			usage(stderr);
+			exit(1);
+		}
+	}
 
-	fd = open("/dev/dvb/adapter0/dvr0", O_RDONLY);
+	snprintf(demux_devname, sizeof demux_devname,
+		 "/dev/dvb/adapter%d/demux%d", adapter, demux);
+	snprintf(dvr_devname, sizeof dvr_devname,
+		 "/dev/dvb/adapter%d/dvr%d", adapter, demux);
+
+	fd = open(dvr_devname, O_RDONLY);
+	if (fd < 0) {
+		fprintf(stderr, "dvbtraffic: Could not open dvr device '%s': %m\n",
+			dvr_devname);
+		exit(1);
+	}
 
 	ioctl(fd, DMX_SET_BUFFER_SIZE, 1024 * 1024);
 
-	ffd = open("/dev/dvb/adapter0/demux0", O_RDWR);
+	ffd = open(demux_devname, O_RDWR);
 	if (ffd < 0) {
-		perror("/dev/dvb/adapter0/demux0");
-		return -fd;
+		fprintf(stderr, "dvbtraffic: Could not open demux device '%s': %m\n",
+			demux_devname);
+		exit(1);
 	}
 
 	flt.pid = 0x2000;
@@ -52,19 +96,17 @@
 
 	gettimeofday(&startt, 0);
 
-	if (argc > 1)
-		search = argv[1];
-	else
-		search = 0;
-
 	while (1) {
+		unsigned char buffer[BSIZE];
 		int pid, r, ok;
-		if ((r = read(fd, buffer, 188)) <= 0) {
+		ssize_t r;
+
+		if ((r = read(fd, buffer, BSIZE)) <= 0) {
 			perror("read");
 			break;
 		}
-		if (r != 188) {
-			printf("only read %d\n", r);
+		if (r != BSIZE) {
+			fprintf(stderr, "dvbtraffic: only read %zd bytes\n", r);
 			break;
 		}
 		if (buffer[0] != 0x47) {




More information about the linux-dvb mailing list