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
 		ts->is_cw_error = 1;
185
 		ts->is_cw_error = 1;
186
 		if (ts->key.ts && now - ts->key.ts > KEY_VALID_TIME) {
186
 		if (ts->key.ts && now - ts->key.ts > KEY_VALID_TIME) {
187
 			if (c->key->is_valid_cw) {
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
 					notify(ts, "NO_CODE_WORD", "No code word was set in %ld sec. Decryption is disabled.",
189
 					notify(ts, "NO_CODE_WORD", "No code word was set in %ld sec. Decryption is disabled.",
190
 						now - ts->key.ts);
190
 						now - ts->key.ts);
191
 					ts_LOGf("CW  | *ERR* No valid code word was received in %ld seconds. Decryption is disabled.\n",
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
 	pidmap_clear(&ts->cc);
48
 	pidmap_clear(&ts->cc);
49
 	pidmap_clear(&ts->pid_seen);
49
 	pidmap_clear(&ts->pid_seen);
50
 
50
 
51
+	ts->have_valid_pmt = 1;
52
+	ts->last_pmt_ts = time(NULL);
53
+
51
 	// Key
54
 	// Key
52
 	memset(&ts->key, 0, sizeof(ts->key));
55
 	memset(&ts->key, 0, sizeof(ts->key));
53
 	ts->key.csakey = csa_key_alloc();
56
 	ts->key.csakey = csa_key_alloc();

+ 5
- 0
data.h View File

257
 	pidmap_t			cc; // Continuity counters
257
 	pidmap_t			cc; // Continuity counters
258
 	pidmap_t			pid_seen;
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
 	// Stats
265
 	// Stats
261
 	unsigned int		emm_input_count;
266
 	unsigned int		emm_input_count;
262
 	unsigned int		emm_seen_count;
267
 	unsigned int		emm_seen_count;

+ 3
- 1
process.c View File

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

+ 4
- 0
tables.c View File

131
 	if (!pid || pid != ts->pmt_pid)
131
 	if (!pid || pid != ts->pmt_pid)
132
 		return;
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
 	handle_table_changes(pmt);
138
 	handle_table_changes(pmt);
135
 
139
 
136
 	pidmap_clear(&ts->pidmap);
140
 	pidmap_clear(&ts->pidmap);

+ 6
- 0
tsdecrypt.1 View File

335
 
335
 
336
   \fBSTART\fR           tsdecrypt was started.
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
   \fBCODE_WORD_OK\fR    Valid code word was received and decryption is
344
   \fBCODE_WORD_OK\fR    Valid code word was received and decryption is
339
                   working ok.
345
                   working ok.
340
 
346
 

+ 13
- 2
tsdecrypt.c View File

861
 }
861
 }
862
 
862
 
863
 static void report_ecms(struct ts *ts, time_t now) {
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
 		return;
865
 		return;
866
 	ts_LOGf("ECM | Received %u (%u dup) and processed %u in %lu seconds.\n",
866
 	ts_LOGf("ECM | Received %u (%u dup) and processed %u in %lu seconds.\n",
867
 		ts->ecm_seen_count,
867
 		ts->ecm_seen_count,
875
 }
875
 }
876
 
876
 
877
 static void report_cw_warn(struct ts *ts, time_t now) {
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
 		return;
879
 		return;
880
 	if (now - ts->key.ts > 1) {
880
 	if (now - ts->key.ts > 1) {
881
 		notify(ts, "NO_CODE_WORD", "No valid code word was received in %ld sec.",
881
 		notify(ts, "NO_CODE_WORD", "No valid code word was received in %ld sec.",
919
 			report_cw_warn(ts, now);
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
 static struct ts ts;
933
 static struct ts ts;
1051
 							ts.rtp_input ? "rtp" : "udp",
1060
 							ts.rtp_input ? "rtp" : "udp",
1052
 							ts.input.hostname, ts.input.service);
1061
 							ts.input.hostname, ts.input.service);
1053
 				}
1062
 				}
1063
+				ts.no_input = 1;
1054
 				ntimeouts++;
1064
 				ntimeouts++;
1055
 			} else {
1065
 			} else {
1056
 				if (ntimeouts && readen > 0) {
1066
 				if (ntimeouts && readen > 0) {
1060
 							ts.rtp_input ? "rtp" : "udp",
1070
 							ts.rtp_input ? "rtp" : "udp",
1061
 							ts.input.hostname, ts.input.service,
1071
 							ts.input.hostname, ts.input.service,
1062
 							(now - timeout_start) + 2); // Timeout is detected when ~2 seconds there is no incoming data
1072
 							(now - timeout_start) + 2); // Timeout is detected when ~2 seconds there is no incoming data
1073
+					ts.no_input = 0;
1063
 					ntimeouts = 0;
1074
 					ntimeouts = 0;
1064
 				}
1075
 				}
1065
 			}
1076
 			}

Loading…
Cancel
Save