Browse Source

Add support for PID filtering on output

Georgi Chorbadzhiyski 13 years ago
parent
commit
0c02899c84
2 changed files with 27 additions and 8 deletions
  1. 1
    1
      libts
  2. 26
    7
      tsdecrypt.c

+ 1
- 1
libts

@@ -1 +1 @@
1
-Subproject commit a0ebea40a64bcc888a995fcda7ad89a5c442d5d9
1
+Subproject commit 69322e5eeff4826d5faceb0bcaef442f15fe5dab

+ 26
- 7
tsdecrypt.c View File

@@ -46,6 +46,7 @@ struct ts {
46 46
 	uint16_t			emm_caid, emm_pid;
47 47
 	uint16_t			ecm_caid, ecm_pid;
48 48
 	uint16_t			ecm_counter;
49
+	pidmap_t			pidmap;
49 50
 };
50 51
 
51 52
 struct ts *ts_alloc() {
@@ -64,6 +65,9 @@ struct ts *ts_alloc() {
64 65
 
65 66
 	ts->ecm      = ts_privsec_alloc();
66 67
 	ts->last_ecm = ts_privsec_alloc();
68
+
69
+	pidmap_clear(&ts->pidmap);
70
+
67 71
 	return ts;
68 72
 }
69 73
 
@@ -136,7 +140,7 @@ AES_KEY camd35_aes_encrypt_key;
136 140
 AES_KEY camd35_aes_decrypt_key;
137 141
 
138 142
 int emm_send = 1;
139
-int pid_filter = 1;
143
+int pid_filter = 0;
140 144
 
141 145
 struct in_addr output_addr;
142 146
 unsigned int output_port;
@@ -480,11 +484,22 @@ void process_cat(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
480 484
 }
481 485
 
482 486
 void process_pmt(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
487
+	int i;
483 488
 	if (!pid || pid != ts->pmt_pid)
484 489
 		return;
485 490
 
486 491
 	handle_table_changes(pmt);
487 492
 
493
+	pidmap_clear(&ts->pidmap);
494
+	pidmap_set(&ts->pidmap, 0x0000); // PAT
495
+	pidmap_set(&ts->pidmap, 0x0011); // SDT
496
+	pidmap_set(&ts->pidmap, ts->pmt->ts_header.pid); // PMT PID
497
+	pidmap_set(&ts->pidmap, ts->pmt->PCR_pid); // PCR
498
+	for (i=0;i<ts->pmt->streams_num;i++) {
499
+		struct ts_pmt_stream *stream = ts->pmt->streams[i];
500
+		pidmap_set(&ts->pidmap, stream->pid); // Data
501
+	}
502
+
488 503
 	if (!ts->ecm_caid) {
489 504
 		ts_get_ecm_info(ts->pmt, req_CA_sys, &ts->ecm_caid, &ts->ecm_pid);
490 505
 		char *CA_sys = ts_get_CA_sys_txt(ts_get_CA_sys(ts->ecm_caid));
@@ -588,6 +603,10 @@ void ts_process_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
588 603
 				// scramble_idx 3 == odd key
589 604
 				ts_packet_set_not_scrambled(ts_packet);
590 605
 				dvbcsa_decrypt(csakey[scramble_idx - 2], ts_packet + 4, 184);
606
+			} else {
607
+				// Can't decrypt the packet just make it NULL packet
608
+				if (pid_filter)
609
+					ts_packet_set_pid(ts_packet, 0x1fff);
591 610
 			}
592 611
 		}
593 612
 
@@ -596,17 +615,17 @@ void ts_process_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
596 615
 }
597 616
 
598 617
 void ts_write_packets(struct ts *ts, uint8_t *data, ssize_t data_len) {
599
-	ts = ts;
600
-	write(1, data, data_len);
601
-	return;
602
-/*
603 618
 	ssize_t i;
604 619
 	for (i=0; i<data_len; i += 188) {
605 620
 		uint8_t *ts_packet = data + i;
606 621
 		uint16_t pid = ts_packet_get_pid(ts_packet);
607
-		write(1, ts_packet, 188);
622
+		if (pid_filter) {
623
+			if (pidmap_get(&ts->pidmap, pid)) // PAT or allowed PIDs
624
+				write(1, ts_packet, 188);
625
+		} else {
626
+			write(1, ts_packet, 188);
627
+		}
608 628
 	}
609
-*/
610 629
 }
611 630
 
612 631
 #define FRAME_SIZE (188 * 7)

Loading…
Cancel
Save