1 /*
2
3 This file is part of libdvbcsa.
4
5 libdvbcsa is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 libdvbcsa is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libdvbcsa; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 */
20
21 #include <time.h>
22 #include <sys/time.h>
23 #include <stdio.h>
24
25 #ifdef __linux__
26 #include <sched.h>
27 #endif
28
29 #include <dvbcsa/dvbcsa.h>
30 #include "dvbcsa_pv.h"
31
32 #ifdef HAVE_ASSERT_H
33 #include <assert.h>
34 #endif
35
36 #define TS_SIZE 184
37
38 int
main(void)39 main (void)
40 {
41 struct timeval t0, t1;
42 struct dvbcsa_key_s *key = dvbcsa_key_alloc();
43 unsigned int n, i, c = 0;
44 uint8_t data[256];
45 dvbcsa_cw_t cw = { 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, };
46
47 #ifdef HAVE_ASSERT_H
48 assert(key != NULL);
49 #endif
50
51 #ifdef __linux__
52 struct sched_param sp = { .sched_priority = 1 };
53
54 sched_setscheduler (0, SCHED_FIFO, &sp);
55 #endif
56
57 puts("* CSA encryption bench *");
58
59 for (i = 0; i < sizeof(dvbcsa_cw_t); i++)
60 cw[i] = i * 3 ^ 0x55;
61
62 memset(data, 0, TS_SIZE);
63
64 dvbcsa_key_set(cw, key);
65
66 gettimeofday(&t0, NULL);
67
68 for (n = 256; n < 1 << 16; n *= 2)
69 {
70 printf(" benchmarking with %u TS packets\n", n);
71
72 #ifdef __linux__
73 sched_yield();
74 #endif
75
76 for (i = 0; i < n; i++)
77 dvbcsa_encrypt(key, data, TS_SIZE);
78
79 c += n;
80 }
81
82 gettimeofday(&t1, NULL);
83
84 printf(" - %u packets proceded, %.1f Mbits/s\n\n", c,
85 (float)(c * 184 * 8) / (float)((t1.tv_sec * 1000000 + t1.tv_usec) - (t0.tv_sec * 1000000 + t0.tv_usec))
86 );
87
88 dvbcsa_key_free(key);
89
90 puts("* Done *");
91
92 return (0);
93 }
94
95