Browse Source

Add another error NO_PROGRAM error when PMT is missing from the input

Georgi Chorbadzhiyski 7 years ago
parent
commit
39d57e595c
7 changed files with 35 additions and 4 deletions
  1. 1
    1
      camd.c
  2. 3
    0
      data.c
  3. 5
    0
      data.h
  4. 3
    1
      process.c
  5. 4
    0
      tables.c
  6. 6
    0
      tsdecrypt.1
  7. 13
    2
      tsdecrypt.c

+ 1
- 1
camd.c View File

@@ -185,7 +185,7 @@ static int camd_send_ecm(struct ts *ts, struct camd_msg *msg) {
185 185
 		ts->is_cw_error = 1;
186 186
 		if (ts->key.ts && now - ts->key.ts > KEY_VALID_TIME) {
187 187
 			if (c->key->is_valid_cw) {
188
-				if (!ts->stream_is_not_scrambled) {
188
+				if (!ts->stream_is_not_scrambled || !ts->have_valid_pmt) {
189 189
 					notify(ts, "NO_CODE_WORD", "No code word was set in %ld sec. Decryption is disabled.",
190 190
 						now - ts->key.ts);
191 191
 					ts_LOGf("CW  | *ERR* No valid code word was received in %ld seconds. Decryption is disabled.\n",

+ 3
- 0
data.c View File

@@ -48,6 +48,9 @@ void data_init(struct ts *ts) {
48 48
 	pidmap_clear(&ts->cc);
49 49
 	pidmap_clear(&ts->pid_seen);
50 50
 
51
+	ts->have_valid_pmt = 1;
52
+	ts->last_pmt_ts = time(NULL);
53
+
51 54
 	// Key
52 55
 	memset(&ts->key, 0, sizeof(ts->key));
53 56
 	ts->key.csakey = csa_key_alloc();

+ 5
- 0
data.h View File

@@ -257,6 +257,11 @@ struct ts {
257 257
 	pidmap_t			cc; // Continuity counters
258 258
 	pidmap_t			pid_seen;
259 259
 
260
+	// PMT tracking
261
+	time_t				last_pmt_ts;
262
+	unsigned int		have_valid_pmt;
263
+	unsigned int		no_input;
264
+
260 265
 	// Stats
261 266
 	unsigned int		emm_input_count;
262 267
 	unsigned int		emm_seen_count;

+ 3
- 1
process.c View File

@@ -132,7 +132,7 @@ static void decode_buffer(struct ts *ts, uint8_t *data, int data_len) {
132 132
 		uint16_t pid = ts_packet_get_pid(ts_packet);
133 133
 		bool in_pidmap = pidmap_get(&ts->pidmap, pid);
134 134
 		bool is_scrambled = ts_packet_is_scrambled(ts_packet);
135
-		if (in_pidmap) {
135
+		if (in_pidmap && ts->have_valid_pmt) {
136 136
 			if (is_scrambled) {
137 137
 				if (ts->last_scrambled_packet_ts < now) {
138 138
 					ts->stream_is_not_scrambled = 0;
@@ -262,6 +262,8 @@ void *decode_thread(void *_ts) {
262 262
 static inline void output_write(struct ts *ts, uint8_t *data, unsigned int data_size) {
263 263
 	if (!data)
264 264
 		return;
265
+	if (!ts->have_valid_pmt)
266
+		return;
265 267
 	if (ts->no_output_on_error && !ts->camd.key->is_valid_cw)
266 268
 		return;
267 269
 	if (!ts->rtp_output) {

+ 4
- 0
tables.c View File

@@ -131,6 +131,10 @@ void process_pmt(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
131 131
 	if (!pid || pid != ts->pmt_pid)
132 132
 		return;
133 133
 
134
+	// Mark PMT as valid and the received timestamp
135
+	ts->last_pmt_ts = time(NULL);
136
+	ts->have_valid_pmt = 1;
137
+
134 138
 	handle_table_changes(pmt);
135 139
 
136 140
 	pidmap_clear(&ts->pidmap);

+ 6
- 0
tsdecrypt.1 View File

@@ -335,6 +335,12 @@ currently defined events are:
335 335
 
336 336
   \fBSTART\fR           tsdecrypt was started.
337 337
 
338
+  \fBNO_PROGRAM\fR    There is an input but there is no valid program
339
+                  in the input (PMT table is missing). This error is
340
+                  reported when there 15 seconds have passed since
341
+                  last valid PMT was received. When this error is
342
+                  active tsdecrypt stops outputing the stream.
343
+
338 344
   \fBCODE_WORD_OK\fR    Valid code word was received and decryption is
339 345
                   working ok.
340 346
 

+ 13
- 2
tsdecrypt.c View File

@@ -861,7 +861,7 @@ static void report_emms(struct ts *ts, time_t now) {
861 861
 }
862 862
 
863 863
 static void report_ecms(struct ts *ts, time_t now) {
864
-	if (ts->stream_is_not_scrambled && ts->ecm_seen_count == 0)
864
+	if ((ts->stream_is_not_scrambled || !ts->have_valid_pmt) && ts->ecm_seen_count == 0)
865 865
 		return;
866 866
 	ts_LOGf("ECM | Received %u (%u dup) and processed %u in %lu seconds.\n",
867 867
 		ts->ecm_seen_count,
@@ -875,7 +875,7 @@ static void report_ecms(struct ts *ts, time_t now) {
875 875
 }
876 876
 
877 877
 static void report_cw_warn(struct ts *ts, time_t now) {
878
-	if (ts->stream_is_not_scrambled)
878
+	if (ts->stream_is_not_scrambled || !ts->have_valid_pmt)
879 879
 		return;
880 880
 	if (now - ts->key.ts > 1) {
881 881
 		notify(ts, "NO_CODE_WORD", "No valid code word was received in %ld sec.",
@@ -919,6 +919,15 @@ static void do_reports(struct ts *ts) {
919 919
 			report_cw_warn(ts, now);
920 920
 		}
921 921
 	}
922
+	if (!ts->no_input) {
923
+		if (ts->last_pmt_ts <= now - 3) {
924
+			if (ts->have_valid_pmt) {
925
+				ts_LOGf("MIS | There is no valid PMT in the input.\n");
926
+				notify(ts, "NO_PROGRAM", "The input is missing valid program.");
927
+				ts->have_valid_pmt = 0;
928
+			}
929
+		}
930
+	}
922 931
 }
923 932
 
924 933
 static struct ts ts;
@@ -1051,6 +1060,7 @@ int main(int argc, char **argv) {
1051 1060
 							ts.rtp_input ? "rtp" : "udp",
1052 1061
 							ts.input.hostname, ts.input.service);
1053 1062
 				}
1063
+				ts.no_input = 1;
1054 1064
 				ntimeouts++;
1055 1065
 			} else {
1056 1066
 				if (ntimeouts && readen > 0) {
@@ -1060,6 +1070,7 @@ int main(int argc, char **argv) {
1060 1070
 							ts.rtp_input ? "rtp" : "udp",
1061 1071
 							ts.input.hostname, ts.input.service,
1062 1072
 							(now - timeout_start) + 2); // Timeout is detected when ~2 seconds there is no incoming data
1073
+					ts.no_input = 0;
1063 1074
 					ntimeouts = 0;
1064 1075
 				}
1065 1076
 			}

Loading…
Cancel
Save