Browse Source

Cleanup internal variables.

This is in preparation for adding --ecm-only and -ecm-and-emm-only
options.
Georgi Chorbadzhiyski 11 years ago
parent
commit
b99eea5149
5 changed files with 60 additions and 70 deletions
  1. 5
    1
      data.c
  2. 5
    2
      data.h
  3. 1
    1
      process.c
  4. 2
    5
      tables.c
  5. 47
    61
      tsdecrypt.c

+ 5
- 1
data.c View File

@@ -72,7 +72,11 @@ void data_init(struct ts *ts) {
72 72
 
73 73
 	ts->debug_level = 0;
74 74
 	ts->req_CA_sys  = CA_CONAX;
75
-	ts->emm_send    = 0;
75
+
76
+	ts->process_ecm = 1;
77
+	ts->process_emm = 0;
78
+	ts->output_stream = 1;
79
+
76 80
 	ts->pid_filter  = 1;
77 81
 
78 82
 	ts->emm_report_interval = 60;

+ 5
- 2
data.h View File

@@ -17,6 +17,7 @@
17 17
 
18 18
 #include <pthread.h>
19 19
 #include <limits.h>
20
+#include <stdbool.h>
20 21
 
21 22
 #include <openssl/aes.h>
22 23
 #include <openssl/des.h>
@@ -270,8 +271,10 @@ struct ts {
270 271
 
271 272
 	enum CA_system		req_CA_sys;
272 273
 
273
-	int					emm_send;
274
-	int					emm_only;
274
+	bool				output_stream;		// Decode and output the decoded stream
275
+	bool				process_ecm;		// Process ECM packets (and send them to CAMD)
276
+	bool				process_emm;		// Process EMM packets (and send them to CAMD)
277
+
275 278
 	int					pid_filter;
276 279
 	int					eit_passthrough;
277 280
 	int					tdt_passthrough;

+ 1
- 1
process.c View File

@@ -359,7 +359,7 @@ void process_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
359 359
 		if (!ts_pack_shown)
360 360
 			dump_ts_pack(ts, pid, ts_packet);
361 361
 
362
-		if (ts->emm_only)
362
+		if (!ts->output_stream)
363 363
 			continue;
364 364
 
365 365
 		// Return rewritten PAT

+ 2
- 5
tables.c View File

@@ -274,9 +274,6 @@ static void __process_emm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
274 274
 
275 275
 	ts->emm_input_count++;
276 276
 
277
-	if (!ts->emm_send)
278
-		return;
279
-
280 277
 	ts->emm = ts_privsec_push_packet(ts->emm, ts_packet);
281 278
 	if (!ts->emm->initialized)
282 279
 		return;
@@ -381,7 +378,7 @@ static void __process_ecm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
381 378
 void process_ecm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
382 379
 	int section_end;
383 380
 
384
-	if (ts->emm_only)
381
+	if (!ts->process_ecm)
385 382
 		return;
386 383
 
387 384
 	if (!ts->ecm_pid || ts->ecm_pid != pid)
@@ -410,7 +407,7 @@ process_psi:
410 407
 void process_emm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
411 408
 	int section_end;
412 409
 
413
-	if (!ts->emm_pid || ts->emm_pid != pid)
410
+	if (!ts->process_emm)
414 411
 		return;
415 412
 
416 413
 process_psi:

+ 47
- 61
tsdecrypt.c View File

@@ -218,7 +218,7 @@ static void show_help(struct ts *ts) {
218 218
 	printf(" -6 --ipv6                  | Use only IPv6 addresses of the camd server.\n");
219 219
 	printf("\n");
220 220
 	printf("EMM options:\n");
221
-	printf(" -e --emm                   | Enable sending EMM's to CAMD. Default: %s\n", ts->emm_send ? "enabled" : "disabled");
221
+	printf(" -e --emm                   | Enable sending EMM's to CAMD. Default: %s\n", ts->process_emm ? "enabled" : "disabled");
222 222
 	printf(" -E --emm-only              | Send only EMMs to CAMD, skipping ECMs and without\n");
223 223
 	printf("                            .   decoding the input stream.\n");
224 224
 	printf(" -Z --emm-pid <pid>         | Force EMM pid. Default: none\n");
@@ -493,14 +493,15 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
493 493
 				break;
494 494
 
495 495
 			case 'e': // --emm
496
-				ts->emm_send = !ts->emm_send;
496
+				ts->process_emm = !ts->process_emm;
497 497
 				break;
498 498
 			case 'Z': // --emm-pid
499 499
 				ts->forced_emm_pid = strtoul(optarg, NULL, 0) & 0x1fff;
500 500
 				break;
501 501
 			case 'E': // --emm-only
502
-				ts->emm_only = 1;
503
-				ts->emm_send = 1;
502
+				ts->process_emm = 1;
503
+				ts->process_ecm = 0;
504
+				ts->output_stream = 0;
504 505
 				break;
505 506
 			case 'f': // --emm-report-time
506 507
 				ts->emm_report_interval = strtoul(optarg, NULL, 10);
@@ -600,10 +601,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
600 601
 		ts->output.type = FILE_IO;
601 602
 		ts->output.fd = 1;
602 603
 		ts->pid_filter = 0;
603
-		ts->emm_send = 1;
604
-		ts->emm_report_interval = 0;
605
-		ts->ecm_report_interval = 0;
606
-		ts->cw_warn_sec = 0;
604
+		ts->process_ecm = 0;
605
+		ts->process_emm = 0;
606
+		ts->output_stream = 0;
607 607
 		ts->camd.no_reconnect = 1;
608 608
 		ts->camd.check_emm_errors = 1;
609 609
 		ts->emm_filters_num = 0;
@@ -612,13 +612,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
612 612
 	// Constant codeword is special. Disable conflicting options
613 613
 	if (ts->camd.constant_codeword) {
614 614
 		server_err = 0; // No server settings are required
615
-		ts->forced_caid = 0;
616
-		ts->forced_ecm_pid = 0;
617
-		ts->forced_emm_pid = 0;
618
-		ts->emm_send = 0;
619
-		ts->emm_report_interval = 0;
620
-		ts->ecm_report_interval = 0;
621
-		ts->cw_warn_sec = 0;
615
+		ts->process_ecm = 0;
616
+		ts->process_emm = 0;
617
+		ts->output_stream = 1;
622 618
 	}
623 619
 
624 620
 	if (ident_err || ca_err || server_err || input_addr_err || output_addr_err || ts->input.type == WTF_IO || ts->output.type == WTF_IO) {
@@ -709,8 +705,7 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
709 705
 	if (ts->req_CA_sys == CA_IRDETO)
710 706
 		ts_LOGf("Irdeto ECM : %d\n", ts->irdeto_ecm);
711 707
 
712
-	if (!ts->emm_only)
713
-	{
708
+	if (ts->output_stream) {
714 709
 		if (ts->output.type == NET_IO) {
715 710
 			ts_LOGf("Output addr: %s://%s:%s/\n",
716 711
 				ts->rtp_output ? "rtp" : "udp",
@@ -727,16 +722,13 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
727 722
 				RAND_bytes((unsigned char *)&(ts->rtp_seqnum), 2);
728 723
 			}
729 724
 		} else if (ts->output.type == FILE_IO) {
730
-			if (!packet_from_file)
731
-				ts_LOGf("Output file: %s\n", ts->output.fd == 1 ? "STDOUT" : ts->output.fname);
732
-		}
733
-		if (!packet_from_file) {
734
-			ts_LOGf("Out filter : %s (%s)%s\n",
735
-				ts->pid_filter ? "enabled" : "disabled",
736
-				ts->pid_filter ? "output only service related PIDs" : "output everything",
737
-				ts->no_output_on_error ? " (No output on CW error)" : ""
738
-			);
725
+			ts_LOGf("Output file: %s\n", ts->output.fd == 1 ? "STDOUT" : ts->output.fname);
739 726
 		}
727
+		ts_LOGf("Out filter : %s (%s)%s\n",
728
+			ts->pid_filter ? "enabled" : "disabled",
729
+			ts->pid_filter ? "output only service related PIDs" : "output everything",
730
+			ts->no_output_on_error ? " (No output on CW error)" : ""
731
+		);
740 732
 		if (ts->pid_filter) {
741 733
 			if (ts->nit_passthrough)
742 734
 				ts_LOGf("Out filter : Pass through NIT.\n");
@@ -745,7 +737,13 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
745 737
 			if (ts->tdt_passthrough)
746 738
 				ts_LOGf("Out filter : Pass through TDT/TOT.\n");
747 739
 		}
740
+		ts_LOGf("TS discont : %s\n", ts->ts_discont ? "report" : "ignore");
741
+		ts->threaded = !(ts->input.type == FILE_IO && ts->input.fd != 0);
742
+		ts_LOGf("Decoding   : %s\n", ts->threaded ? "threaded" : "single thread");
743
+	} else {
744
+		ts_LOGf("Decoding   : disabled\n");
748 745
 	}
746
+
749 747
 	if (!ts->camd.constant_codeword) {
750 748
 		ts_LOGf("CAMD proto : %s\n", ts->camd.ops.ident);
751 749
 		ts_LOGf("CAMD addr  : %s:%s%s\n", ts->camd.hostname, ts->camd.service,
@@ -759,34 +757,18 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
759 757
 			ts_LOGf("CAMD deskey: %s\n", ts->camd.newcamd.hex_des_key);
760 758
 	}
761 759
 
762
-	if (!packet_from_file) {
763
-		ts_LOGf("TS discont : %s\n", ts->ts_discont ? "report" : "ignore");
764
-		ts->threaded = !(ts->input.type == FILE_IO && ts->input.fd != 0);
765
-	}
760
+	if (!packet_from_file)
761
+		ts_LOGf("EMM process: %s\n", ts->process_emm ? "Yes" : "No");
766 762
 
767
-	if (!packet_from_file && !ts->emm_only) {
768
-		ts_LOGf("Decoding   : %s\n", ts->threaded ? "threaded" : "single thread");
769
-	}
770
-
771
-	if (!packet_from_file) {
772
-		if (ts->emm_send && ts->emm_report_interval)
773
-			ts_LOGf("EMM report : %d sec\n", ts->emm_report_interval);
774
-		if (ts->emm_send && ts->emm_report_interval == 0)
775
-			ts_LOGf("EMM report : disabled\n");
763
+	if (ts->process_emm) {
776 764
 		if (ts->forced_emm_pid)
777 765
 			ts_LOGf("EMM pid    : 0x%04x (%d)\n", ts->forced_emm_pid, ts->forced_emm_pid);
778
-	}
779
-	if (ts->emm_only) {
780
-		ts_LOGf("EMM only   : %s\n", ts->emm_only ? "yes" : "no");
781
-	} else {
782
-		if (!packet_from_file) {
783
-			if (!ts->camd.constant_codeword)
784
-				ts_LOGf("EMM send   : %s\n", ts->emm_send   ? "enabled" : "disabled");
785
-			ts_LOGf("Decoding   : %s\n", ts->threaded ? "threaded" : "single thread");
786
-		}
787
-	}
788 766
 
789
-	if (ts->emm_send) {
767
+		if (ts->emm_report_interval)
768
+			ts_LOGf("EMM report : %d sec\n", ts->emm_report_interval);
769
+		else
770
+			ts_LOGf("EMM report : disabled\n");
771
+
790 772
 		for (i = 0; i < ts->emm_filters_num; i++) {
791 773
 			char tmp[512];
792 774
 			filter_dump(&ts->emm_filters[i], tmp, sizeof(tmp));
@@ -794,20 +776,24 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
794 776
 		}
795 777
 	}
796 778
 
797
-	if (!packet_from_file) {
798
-		if (!ts->emm_only && ts->ecm_report_interval)
799
-			ts_LOGf("ECM report : %d sec\n", ts->emm_report_interval);
800
-		if (!ts->emm_only && ts->ecm_report_interval == 0 && !ts->camd.constant_codeword)
801
-			ts_LOGf("ECM report : disabled\n");
779
+	if (!packet_from_file)
780
+		ts_LOGf("ECM process: %s\n", ts->process_ecm ? "Yes" : "No");
781
+
782
+	if (ts->process_ecm) {
802 783
 		if (ts->forced_ecm_pid)
803 784
 			ts_LOGf("ECM pid    : 0x%04x (%d)\n", ts->forced_ecm_pid, ts->forced_ecm_pid);
804 785
 
805
-		if (!ts->emm_only && ts->cw_warn_sec)
786
+		if (ts->ecm_report_interval)
787
+			ts_LOGf("ECM report : %d sec\n", ts->emm_report_interval);
788
+		else
789
+			ts_LOGf("ECM report : disabled\n");
790
+
791
+		if (ts->cw_warn_sec)
806 792
 			ts_LOGf("CW warning : %d sec\n", ts->cw_warn_sec);
807
-		if (!ts->emm_only && ts->cw_warn_sec && !ts->camd.constant_codeword)
793
+		else
808 794
 			ts_LOGf("CW warning : disabled\n");
809 795
 
810
-		if (!ts->ecm_cw_log && !ts->camd.constant_codeword)
796
+		if (!ts->ecm_cw_log)
811 797
 			ts_LOGf("ECM/CW log : disabled\n");
812 798
 	}
813 799
 
@@ -865,7 +851,7 @@ static void do_reports(struct ts *ts) {
865 851
 	static int first_emm_report = 1;
866 852
 	static int first_ecm_report = 1;
867 853
 	time_t now = time(NULL);
868
-	if (ts->emm_send && ts->emm_report_interval) {
854
+	if (ts->process_emm && ts->emm_report_interval) {
869 855
 		if (first_emm_report && now >= ts->emm_last_report) {
870 856
 			first_emm_report = 0;
871 857
 			ts->emm_last_report -= FIRST_REPORT_SEC;
@@ -874,7 +860,7 @@ static void do_reports(struct ts *ts) {
874 860
 			report_emms(ts, now);
875 861
 		}
876 862
 	}
877
-	if (!ts->emm_only && ts->ecm_report_interval) {
863
+	if (ts->process_ecm && ts->ecm_report_interval) {
878 864
 		if (first_ecm_report && now >= ts->ecm_last_report) {
879 865
 			first_ecm_report = 0;
880 866
 			ts->ecm_last_report -= FIRST_REPORT_SEC;
@@ -884,7 +870,7 @@ static void do_reports(struct ts *ts) {
884 870
 		}
885 871
 	}
886 872
 
887
-	if (!ts->emm_only && !ts->key.is_valid_cw) {
873
+	if (ts->process_ecm && !ts->key.is_valid_cw) {
888 874
 		if (ts->cw_warn_sec && now >= ts->cw_next_warn) {
889 875
 			report_cw_warn(ts, now);
890 876
 		}

Loading…
Cancel
Save