diff options
author | etobi <git@e-tobi.net> | 2013-09-03 09:48:41 +0200 |
---|---|---|
committer | etobi <git@e-tobi.net> | 2013-09-03 09:48:41 +0200 |
commit | ab959d7b4194715870128e616b8e29d4a101e488 (patch) | |
tree | 61a746231d30817be73416a7d67763fd677a1042 /util/dvbtraffic/dvbtraffic.c | |
parent | 6b350466c4902c5b137e0efaf1d189128a7f18f5 (diff) | |
download | linux-dvb-apps-753ce5b9809deed38d6db404dc72e1e0e8ac4b29.tar.gz |
Imported Upstream version 1.1.1+rev1207upstream/1.1.1+rev1207
Diffstat (limited to '')
-rw-r--r-- | util/dvbtraffic/dvbtraffic.c | 110 |
1 files changed, 65 insertions, 45 deletions
diff --git a/util/dvbtraffic/dvbtraffic.c b/util/dvbtraffic/dvbtraffic.c index 8add053..b9a151d 100644 --- a/util/dvbtraffic/dvbtraffic.c +++ b/util/dvbtraffic/dvbtraffic.c @@ -1,3 +1,5 @@ +/* This file is released into the public domain by its authors */ + #include <stdio.h> #include <stdlib.h> #include <sys/ioctl.h> @@ -9,64 +11,83 @@ #include <sys/poll.h> #include <sys/time.h> #include <string.h> - -#include <linux/dvb/dmx.h> -#include <linux/dvb/frontend.h> -#include <linux/dvb/video.h> +#include <limits.h> +#include <libdvbapi/dvbdemux.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 adapter N\n" + " -d N use demux N\n" + " -h display this help\n"); +} int main(int argc, char **argv) { - int fd, ffd, packets = 0; struct timeval startt; - struct dmx_pes_filter_params flt; - char *search; - unsigned char buffer[BSIZE]; - - fd = open("/dev/dvb/adapter0/dvr0", O_RDONLY); - - ioctl(fd, DMX_SET_BUFFER_SIZE, 1024 * 1024); + int adapter = 0, demux = 0; + char *search = NULL; + int fd, ffd, packets = 0; + int opt; - ffd = open("/dev/dvb/adapter0/demux0", O_RDWR); - if (ffd < 0) { - perror("/dev/dvb/adapter0/demux0"); - return -fd; + 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); + } } - flt.pid = 0x2000; - flt.input = DMX_IN_FRONTEND; - flt.output = DMX_OUT_TS_TAP; - flt.pes_type = DMX_PES_OTHER; - flt.flags = 0; + // open the DVR device + fd = dvbdemux_open_dvr(adapter, demux, 1, 0); + if (fd < 0) { + fprintf(stderr, "dvbtraffic: Could not open dvr device: %m\n"); + exit(1); + } + dvbdemux_set_buffer(fd, 1024 * 1024); - if (ioctl(ffd, DMX_SET_PES_FILTER, &flt) < 0) { - perror("DMX_SET_PES_FILTER"); - return -1; + ffd = dvbdemux_open_demux(adapter, demux, 0); + if (ffd < 0) { + fprintf(stderr, "dvbtraffic: Could not open demux device: %m\n"); + exit(1); } - if (ioctl(ffd, DMX_START, 0) < 0) { - perror("DMX_SET_PES_FILTER"); + if (dvbdemux_set_pid_filter(ffd, -1, DVBDEMUX_INPUT_FRONTEND, DVBDEMUX_OUTPUT_DVR, 1)) { + perror("dvbdemux_set_pid_filter"); return -1; } gettimeofday(&startt, 0); - if (argc > 1) - search = argv[1]; - else - search = 0; - while (1) { - int pid, r, ok; - if ((r = read(fd, buffer, 188)) <= 0) { + unsigned char buffer[BSIZE]; + int pid, ok; + 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) { @@ -106,16 +127,16 @@ int main(int argc, char **argv) (now.tv_sec - startt.tv_sec) * 1000 + (now.tv_usec - startt.tv_usec) / 1000; if (diff > 1000) { - int pid = 0; - for (pid = 0; pid < 0x2001; pid++) { - if (pidt[pid]) { + int _pid = 0; + for (_pid = 0; _pid < 0x2001; _pid++) { + if (pidt[_pid]) { printf("%04x %5d p/s %5d kb/s %5d kbit\n", - pid, - pidt[pid] * 1000 / diff, - pidt[pid] * 1000 / diff * 188 / 1024, - pidt[pid] * 8 * 1000 / diff * 188 / 1000); + _pid, + pidt[_pid] * 1000 / diff, + pidt[_pid] * 1000 / diff * 188 / 1024, + pidt[_pid] * 8 * 1000 / diff * 188 / 1000); } - pidt[pid] = 0; + pidt[_pid] = 0; } printf("-PID--FREQ-----BANDWIDTH-BANDWIDTH-\n"); startt = now; @@ -127,4 +148,3 @@ int main(int argc, char **argv) close(fd); return 0; } - |