Permalink
Browse files

Add --pid-report option.

  • Loading branch information...
gfto committed Jan 28, 2012
1 parent 60e69f0 commit e560bc39c51dbeca8fa689cdf1a26ddd67e38ecc
Showing with 38 additions and 4 deletions.
  1. +1 −0 ChangeLog
  2. +1 −0 README
  3. +5 −0 data.h
  4. +17 −1 process.c
  5. +1 −0 process.h
  6. +4 −0 tsdecrypt.1
  7. +9 −3 tsdecrypt.c
View
@@ -1,6 +1,7 @@
next : Version next
* Add --output-tos (-g) option used to set output TOS value.
* Add --input-dump (-W) option used save input stream in file.
+ * Add --pid-report (-j) option used to turn on PID reporting.
2011-12-23 : Version 5.0
* Add --bench (-b) option that benchmarks libdvbcsa decryption.
View
1 README
@@ -95,6 +95,7 @@ Misc options:
. 3 = show duplicate ECMs
. 4 = packet debug
. 5 = packet debug + packet dump
+ -j --pid-report | Report how much packets were received.
-b --bench | Benchmark decrypton.
-h --help | Show help screen.
-V --version | Show program version.
View
5 data.h
@@ -173,6 +173,8 @@ struct io {
struct in_addr intf;
};
+#define MAX_PIDS 8192
+
struct ts {
// Stream handling
struct ts_pat *pat, *curpat;
@@ -212,6 +214,9 @@ struct ts {
unsigned int cw_warn_sec;
time_t cw_last_warn;
+ unsigned int pid_report;
+ unsigned int pid_stats[MAX_PIDS];
+
// CAMD handling
struct key key;
struct camd camd;
View
@@ -25,7 +25,7 @@
static unsigned long ts_pack;
static int ts_pack_shown;
-static char *get_pid_desc(struct ts *ts, uint16_t pid) {
+char *get_pid_desc(struct ts *ts, uint16_t pid) {
int i;
uint16_t nitpid = 0x0010, pmtpid = 0xffff, pcrpid = 0xffff;
@@ -266,6 +266,9 @@ void process_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
uint8_t *ts_packet = data + i;
uint16_t pid = ts_packet_get_pid(ts_packet);
+ if (ts->pid_report)
+ ts->pid_stats[pid]++;
+
ts_pack_shown = 0;
process_pat(ts, pid, ts_packet);
@@ -313,3 +316,16 @@ void process_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
ts_pack++;
}
}
+
+void show_pid_report(struct ts *ts) {
+ int i;
+ if (!ts->pid_report)
+ return;
+
+ for (i = 0; i < MAX_PIDS; i++) {
+ if (ts->pid_stats[i]) {
+ ts_LOGf("PID | %8u packets with PID 0x%04x (%4u) %s\n",
+ ts->pid_stats[i], i, i, get_pid_desc(ts, i));
+ }
+ }
+}
View
@@ -21,5 +21,6 @@
void *decode_thread(void *_ts);
void *write_thread(void *_ts);
void process_packets(struct ts *ts, uint8_t *data, ssize_t data_len);
+void show_pid_report(struct ts *ts);
#endif
View
@@ -47,6 +47,10 @@ duplicate ECMs, 4 = packet debug. 5 = packet debug + mpeg ts packet
dump.
Setting higher level enables the levels bellow.
.TP
+\fB\-j\fR, \fB\-\-pid\-report\fR
+When this option is used, tsdecrypt on exit reports how much packets
+were received on each PID.
+.TP
\fB\-b\fR, \fB\-\-bench\fR
Bechmark libdvbcsa decryption. The benchmark is single threaded.
If you want to fully test your CPU, run couple of tsdecrypts in parallel.
View
@@ -103,7 +103,7 @@ void run_benchmark(void) {
puts("* Done *");
}
-// Unused short options: FQTYajkmnqruv0123456789
+// Unused short options: FQTYakmnqruv0123456789
static const struct option long_options[] = {
{ "ident", required_argument, NULL, 'i' },
{ "daemon", required_argument, NULL, 'd' },
@@ -149,6 +149,7 @@ static const struct option long_options[] = {
{ "cw-warn-time", required_argument, NULL, 'J' },
{ "debug", required_argument, NULL, 'D' },
+ { "pid-report", no_argument, NULL, 'j' },
{ "bench", no_argument, NULL, 'b' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
@@ -237,6 +238,7 @@ static void show_help(struct ts *ts) {
printf(" . 3 = show duplicate ECMs\n");
printf(" . 4 = packet debug\n");
printf(" . 5 = packet debug + packet dump\n");
+ printf(" -j --pid-report | Report how much packets were received.\n");
printf(" -b --bench | Benchmark decrypton.\n");
printf(" -h --help | Show help screen.\n");
printf(" -V --version | Show program version.\n");
@@ -268,7 +270,7 @@ static int parse_io_param(struct io *io, char *opt, int open_flags, mode_t open_
static void parse_options(struct ts *ts, int argc, char **argv) {
int j, i, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0, ident_err = 0, port_set = 0;
- while ( (j = getopt_long(argc, argv, "i:d:N:Sl:L:I:RzM:W:O:o:t:g:pwxyc:C:A:s:U:P:B:eZ:Ef:X:H:G:KJ:D:bhV", long_options, NULL)) != -1 ) {
+ while ( (j = getopt_long(argc, argv, "i:d:N:Sl:L:I:RzM:W:O:o:t:g:pwxyc:C:A:s:U:P:B:eZ:Ef:X:H:G:KJ:D:jbhV", long_options, NULL)) != -1 ) {
char *p = NULL;
switch (j) {
case 'i':
@@ -444,7 +446,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
case 'D':
ts->debug_level = atoi(optarg);
break;
-
+ case 'j':
+ ts->pid_report = 1;
+ break;
case 'b':
run_benchmark();
exit(EXIT_SUCCESS);
@@ -792,6 +796,8 @@ int main(int argc, char **argv) {
pthread_join(ts.write_thread, NULL);
}
+ show_pid_report(&ts);
+
notify_sync(&ts, "STOP", "Stopping %s", program_id);
ts_LOGf("Stop %s\n", program_id);

0 comments on commit e560bc3

Please sign in to comment.