From ab959d7b4194715870128e616b8e29d4a101e488 Mon Sep 17 00:00:00 2001 From: etobi Date: Tue, 3 Sep 2013 09:48:41 +0200 Subject: Imported Upstream version 1.1.1+rev1207 --- util/dvbtraffic/Makefile | 17 +++++-- util/dvbtraffic/dvbtraffic.c | 110 +++++++++++++++++++++++++------------------ 2 files changed, 78 insertions(+), 49 deletions(-) (limited to 'util/dvbtraffic') diff --git a/util/dvbtraffic/Makefile b/util/dvbtraffic/Makefile index c29be40..b9a8e82 100644 --- a/util/dvbtraffic/Makefile +++ b/util/dvbtraffic/Makefile @@ -1,6 +1,15 @@ +# Makefile for linuxtv.org dvb-apps/util/dvbtraffic -dvbtraffic: dvbtraffic.c - gcc -MD -g -O2 -Wall -I../../include $< -o $@ +binaries = dvbtraffic -clean: - rm -f *.o *.d dvbtraffic +inst_bin = $(binaries) + +CPPFLAGS += -I../../lib +LDFLAGS += -L../../lib/libdvbapi +LDLIBS += -ldvbapi + +.PHONY: all + +all: $(binaries) + +include ../../Make.rules 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 #include #include @@ -9,64 +11,83 @@ #include #include #include - -#include -#include -#include +#include +#include #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; } - -- cgit v1.2.3