~ubuntu-branches/ubuntu/dapper/linuxtv-dvb-apps/dapper

« back to all changes in this revision

Viewing changes to util/dvbtraffic/dvbtraffic.c

  • Committer: Package Import Robot
  • Author(s): Debian VDR Team
  • Date: 2004-10-16 10:01:14 UTC
  • Revision ID: package-import@ubuntu.com-20041016100114-8k4jl1wc9t3re5lw
Tags: upstream-1.1.0
ImportĀ upstreamĀ versionĀ 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <sys/ioctl.h>
 
4
#include <unistd.h>
 
5
#include <sys/types.h>
 
6
#include <sys/stat.h>
 
7
#include <fcntl.h>
 
8
#include <time.h>
 
9
#include <sys/poll.h>
 
10
#include <sys/time.h>
 
11
#include <string.h>
 
12
 
 
13
#include <linux/dvb/dmx.h>
 
14
#include <linux/dvb/frontend.h>
 
15
#include <linux/dvb/video.h>
 
16
 
 
17
#define BSIZE 188
 
18
 
 
19
int pidt[0x2001];
 
20
 
 
21
int main(int argc, char **argv)
 
22
{
 
23
        int fd, ffd, packets = 0;
 
24
        struct timeval startt;
 
25
        struct dmx_pes_filter_params flt;
 
26
        char *search;
 
27
        unsigned char buffer[BSIZE];
 
28
 
 
29
        fd = open("/dev/dvb/adapter0/dvr0", O_RDONLY);
 
30
 
 
31
        ioctl(fd, DMX_SET_BUFFER_SIZE, 1024 * 1024);
 
32
 
 
33
        ffd = open("/dev/dvb/adapter0/demux0", O_RDWR);
 
34
        if (ffd < 0) {
 
35
                perror("/dev/dvb/adapter0/demux0");
 
36
                return -fd;
 
37
        }
 
38
 
 
39
        flt.pid = 0x2000;
 
40
        flt.input = DMX_IN_FRONTEND;
 
41
        flt.output = DMX_OUT_TS_TAP;
 
42
        flt.pes_type = DMX_PES_OTHER;
 
43
        flt.flags = 0;
 
44
 
 
45
        if (ioctl(ffd, DMX_SET_PES_FILTER, &flt) < 0) {
 
46
                perror("DMX_SET_PES_FILTER");
 
47
                return -1;
 
48
        }
 
49
 
 
50
        if (ioctl(ffd, DMX_START, 0) < 0) {
 
51
                perror("DMX_SET_PES_FILTER");
 
52
                return -1;
 
53
        }
 
54
 
 
55
        gettimeofday(&startt, 0);
 
56
 
 
57
        if (argc > 1)
 
58
                search = argv[1];
 
59
        else
 
60
                search = 0;
 
61
 
 
62
        while (1) {
 
63
                int pid, r, ok;
 
64
                if ((r = read(fd, buffer, 188)) <= 0) {
 
65
                        perror("read");
 
66
                        break;
 
67
                }
 
68
                if (r != 188) {
 
69
                        printf("only read %d\n", r);
 
70
                        break;
 
71
                }
 
72
                if (buffer[0] != 0x47) {
 
73
                        continue;
 
74
                        printf("desync (%x)\n", buffer[0]);
 
75
                        while (buffer[0] != 0x47)
 
76
                                read(fd, buffer, 1);
 
77
                        continue;
 
78
                }
 
79
                ok = 1;
 
80
                pid = ((((unsigned) buffer[1]) << 8) |
 
81
                       ((unsigned) buffer[2])) & 0x1FFF;
 
82
 
 
83
                if (search) {
 
84
                        int i, sl = strlen(search);
 
85
                        ok = 0;
 
86
                        if (pid != 0x1fff) {
 
87
                                for (i = 0; i < (188 - sl); ++i) {
 
88
                                        if (!memcmp(buffer + i, search, sl))
 
89
                                                ok = 1;
 
90
                                }
 
91
                        }
 
92
                }
 
93
 
 
94
                if (ok) {
 
95
                        pidt[pid]++;
 
96
                        pidt[0x2000]++;
 
97
                }
 
98
 
 
99
                packets++;
 
100
 
 
101
                if (!(packets & 0xFF)) {
 
102
                        struct timeval now;
 
103
                        int diff;
 
104
                        gettimeofday(&now, 0);
 
105
                        diff =
 
106
                            (now.tv_sec - startt.tv_sec) * 1000 +
 
107
                            (now.tv_usec - startt.tv_usec) / 1000;
 
108
                        if (diff > 1000) {
 
109
                                int pid = 0;
 
110
                                for (pid = 0; pid < 0x2001; pid++) {
 
111
                                        if (pidt[pid]) {
 
112
                                                printf("%04x %5d p/s %5d kb/s %5d kbit\n",
 
113
                                                     pid,
 
114
                                                     pidt[pid] * 1000 / diff,
 
115
                                                     pidt[pid] * 1000 / diff * 188 / 1024,
 
116
                                                     pidt[pid] * 8 * 1000 / diff * 188 / 1000);
 
117
                                        }
 
118
                                        pidt[pid] = 0;
 
119
                                }
 
120
                                printf("-PID--FREQ-----BANDWIDTH-BANDWIDTH-\n");
 
121
                                startt = now;
 
122
                        }
 
123
                }
 
124
        }
 
125
 
 
126
        close(ffd);
 
127
        close(fd);
 
128
        return 0;
 
129
}
 
130