Browse Source

Move EMM reports processing into main thread.

This move is in preparation for adding ecm reports.
Georgi Chorbadzhiyski 12 years ago
parent
commit
6915d654dd
5 changed files with 42 additions and 32 deletions
  1. 5
    12
      camd.c
  2. 3
    2
      data.c
  3. 6
    5
      data.h
  4. 2
    2
      tsdecrypt.1
  5. 26
    11
      tsdecrypt.c

+ 5
- 12
camd.c View File

@@ -275,26 +275,19 @@ static int camd35_send_emm(struct ts *ts, uint16_t ca_id, uint8_t *data, uint8_t
275 275
 	if (ret <= 0) {
276 276
 		ts_LOGf("EMM | Error sending packet.\n");
277 277
 		camd35_reconnect(ts);
278
-	} else {
279
-		c->emm_count++;
280 278
 	}
281 279
 	return ret;
282 280
 }
283 281
 
284 282
 static void camd_do_msg(struct camd_msg *msg) {
285
-	struct camd35 *c = &msg->ts->camd35;
286
-	if (msg->type == EMM_MSG)
287
-		camd35_send_emm(msg->ts, msg->ca_id, msg->data, msg->data_len);
283
+	if (msg->type == EMM_MSG) {
284
+		msg->ts->emm_seen_count++;
285
+		if (camd35_send_emm(msg->ts, msg->ca_id, msg->data, msg->data_len) > 0)
286
+			msg->ts->emm_processed_count++;
287
+	}
288 288
 	if (msg->type == ECM_MSG)
289 289
 		camd35_send_ecm(msg->ts, msg->ca_id, msg->service_id, msg->idx, msg->data, msg->data_len);
290 290
 
291
-	if (msg->ts->emm_send && c->emm_count_report_interval && c->emm_count_last_report + c->emm_count_report_interval <= time(NULL))
292
-	{
293
-		ts_LOGf("EMM | Send %d messages in %d seconds.\n", c->emm_count, c->emm_count_report_interval);
294
-		c->emm_count = 0;
295
-		c->emm_count_last_report = time(NULL);
296
-	}
297
-
298 291
 	camd_msg_free(&msg);
299 292
 }
300 293
 

+ 3
- 2
data.c View File

@@ -62,8 +62,6 @@ void data_init(struct ts *ts) {
62 62
 	ts->camd35.key          = &ts->key;
63 63
 	strcpy(ts->camd35.user, "user");
64 64
 	strcpy(ts->camd35.pass, "pass");
65
-	ts->camd35.emm_count_report_interval = 60;
66
-	ts->camd35.emm_count_last_report     = time(NULL);
67 65
 
68 66
 	// Config
69 67
 	ts->syslog_port = 514;
@@ -78,6 +76,9 @@ void data_init(struct ts *ts) {
78 76
 
79 77
 	ts->packet_delay = 0;
80 78
 
79
+	ts->emm_report_interval = 60;
80
+	ts->emm_last_report     = time(NULL);
81
+
81 82
 	ts->input.fd    = 0; // STDIN
82 83
 	ts->input.type  = FILE_IO;
83 84
 

+ 6
- 5
data.h View File

@@ -56,11 +56,6 @@ struct camd35 {
56 56
 	unsigned int	server_port;
57 57
 	char			user[64];
58 58
 	char			pass[64];
59
-
60
-	int				emm_count;
61
-	int				emm_count_report_interval;
62
-	time_t			emm_count_last_report;
63
-
64 59
 	AES_KEY			aes_encrypt_key;
65 60
 	AES_KEY			aes_decrypt_key;
66 61
 
@@ -109,6 +104,12 @@ struct ts {
109 104
 	pidmap_t			cc; // Continuity counters
110 105
 	pidmap_t			pid_seen;
111 106
 
107
+	// Stats
108
+	unsigned int		emm_seen_count;
109
+	unsigned int		emm_processed_count;
110
+	unsigned int		emm_report_interval;
111
+	time_t				emm_last_report;
112
+
112 113
 	// CAMD handling
113 114
 	struct key			key;
114 115
 	struct camd35		camd35;

+ 2
- 2
tsdecrypt.1 View File

@@ -115,8 +115,8 @@ stream has very high rate and is interfering with ECM processing. Using
115 115
 --emm-only you can run special tsdecrypt dedicated only to card auto update.
116 116
 .TP
117 117
 \fB\-f\fR, \fB\-\-emm\-report\-time\fR <seconds>
118
-Set interval for EMM totals report message. The default is \fB60\fR seconds.
119
-Set to \fB0\fR to disable EMM reporting.
118
+Set interval for EMM reports. The default is \fB60\fR seconds. Set to \fB0\fR
119
+to disable EMM reports.
120 120
 .TP
121 121
 .SH ECM OPTIONS
122 122
 .PP

+ 26
- 11
tsdecrypt.c View File

@@ -127,9 +127,9 @@ static void show_help(struct ts *ts) {
127 127
 	printf(" -E --emm-only              | Send only EMMs to CAMD, skipping ECMs and without\n");
128 128
 	printf("                            . decoding the input stream.\n");
129 129
 	printf(" -Z --emm-pid <pid>         | Force EMM pid. Default: none\n");
130
-	printf(" -f --emm-report-time <sec> | Report how much EMMs has been send for processing\n");
131
-	printf("                            . each <sec> seconds. Set <sec> to 0 to disable\n");
132
-	printf("                            . reporting. Default: %d sec\n", ts->camd35.emm_count_report_interval);
130
+	printf(" -f --emm-report-time <sec> | Report each <sec> seconds how much EMMs have been\n");
131
+	printf("                            . received/processed. Set <sec> to 0 to disable\n");
132
+	printf("                            . the reports. Default: %d sec\n", ts->emm_report_interval);
133 133
 	printf("\n");
134 134
 	printf("ECM options:\n");
135 135
 	printf(" -X --ecm-pid <pid>         | Force ECM pid. Default: none\n");
@@ -276,11 +276,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
276 276
 				ts->emm_send = 1;
277 277
 				break;
278 278
 			case 'f':
279
-				ts->camd35.emm_count_report_interval = atoi(optarg);
280
-				if (ts->camd35.emm_count_report_interval < 0)
281
-					ts->camd35.emm_count_report_interval = 0;
282
-				if (ts->camd35.emm_count_report_interval > 86400)
283
-					ts->camd35.emm_count_report_interval = 86400;
279
+				ts->emm_report_interval = strtoul(optarg, NULL, 10);
280
+				if (ts->emm_report_interval > 86400)
281
+					ts->emm_report_interval = 86400;
284 282
 				break;
285 283
 
286 284
 			case 'X':
@@ -367,9 +365,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
367 365
 		ts_LOGf("Pkt sleep  : %d us (%d ms)\n", ts->packet_delay, ts->packet_delay / 1000);
368 366
 	ts_LOGf("TS discont : %s\n", ts->ts_discont ? "report" : "ignore");
369 367
 	ts->threaded = !(ts->input.type == FILE_IO && ts->input.fd != 0);
370
-	if (ts->emm_send && ts->camd35.emm_count_report_interval)
371
-		ts_LOGf("EMM report : %d sec\n", ts->camd35.emm_count_report_interval);
372
-	if (ts->emm_send && ts->camd35.emm_count_report_interval == 0)
368
+	if (ts->emm_send && ts->emm_report_interval)
369
+		ts_LOGf("EMM report : %d sec\n", ts->emm_report_interval);
370
+	if (ts->emm_send && ts->emm_report_interval == 0)
373 371
 		ts_LOGf("EMM report : disabled\n");
374 372
 	if (ts->emm_only) {
375 373
 		ts_LOGf("EMM only   : %s\n", ts->emm_only ? "yes" : "no");
@@ -389,6 +387,21 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
389 387
 	}
390 388
 }
391 389
 
390
+static void do_reports(struct ts *ts) {
391
+	time_t now = time(NULL);
392
+	if (ts->emm_send && ts->emm_report_interval) {
393
+		if ((time_t)(ts->emm_last_report + ts->emm_report_interval) <= now) {
394
+			ts->emm_last_report = now;
395
+			ts_LOGf("EMM | Received %u and processed %u in %u seconds.\n",
396
+				ts->emm_seen_count,
397
+				ts->emm_processed_count,
398
+				ts->emm_report_interval);
399
+			ts->emm_seen_count = 0;
400
+			ts->emm_processed_count = 0;
401
+		}
402
+	}
403
+}
404
+
392 405
 void signal_quit(int sig) {
393 406
 	if (!keep_running)
394 407
 		raise(sig);
@@ -444,6 +457,8 @@ int main(int argc, char **argv) {
444 457
 
445 458
 	camd_start(&ts);
446 459
 	do {
460
+		do_reports(&ts);
461
+
447 462
 		if (ts.input.type == NET_IO) {
448 463
 			set_log_io_errors(0);
449 464
 			if (!ts.rtp_input) {

Loading…
Cancel
Save