Browse Source

Add functions to get ecm and emm info by caid and by pid.

Georgi Chorbadzhiyski 8 years ago
parent
commit
e9ba8bcf8f
2 changed files with 87 additions and 0 deletions
  1. 81 0
      cat.c
  2. 6 0
      tsfuncs.h

+ 81 - 0
cat.c View File

@@ -251,3 +251,84 @@ int ts_get_ecm_info(struct ts_pmt *pmt, enum CA_system req_CA_type, uint16_t *CA
251 251
 
252 252
 	return result;
253 253
 }
254
+
255
+static int find_CA_descriptor_by_caid(uint8_t *data, int data_len, uint16_t caid, uint16_t *CA_pid) {
256
+	while (data_len >= 2) {
257
+		uint8_t tag         = data[0];
258
+		uint8_t this_length = data[1];
259
+		data     += 2;
260
+		data_len -= 2;
261
+		if (tag == 9 && this_length >= 4) {
262
+			uint16_t CA_ID = (data[0] << 8) | data[1];
263
+			uint16_t CA_PID = ((data[2] & 0x1F) << 8) | data[3];
264
+			if (CA_ID == caid) {
265
+				*CA_pid = CA_PID;
266
+				return 1;
267
+			}
268
+		}
269
+		data_len -= this_length;
270
+		data += this_length;
271
+	}
272
+	return 0;
273
+}
274
+
275
+int ts_get_emm_info_by_caid(struct ts_cat *cat, uint16_t caid, uint16_t *ca_pid) {
276
+	return find_CA_descriptor_by_caid(cat->program_info, cat->program_info_size, caid, ca_pid);
277
+}
278
+
279
+int ts_get_ecm_info_by_caid(struct ts_pmt *pmt, uint16_t caid, uint16_t *ca_pid) {
280
+	int i, result = find_CA_descriptor_by_caid(pmt->program_info, pmt->program_info_size, caid, ca_pid);
281
+	if (!result) {
282
+		for(i=0;i<pmt->streams_num;i++) {
283
+			struct ts_pmt_stream *stream = pmt->streams[i];
284
+			if (stream->ES_info) {
285
+				result = find_CA_descriptor_by_caid(stream->ES_info, stream->ES_info_size, caid, ca_pid);
286
+				if (result)
287
+					break;
288
+			}
289
+		}
290
+	}
291
+
292
+	return result;
293
+}
294
+
295
+
296
+static int find_CA_descriptor_by_pid(uint8_t *data, int data_len, uint16_t *caid, uint16_t pid) {
297
+	while (data_len >= 2) {
298
+		uint8_t tag         = data[0];
299
+		uint8_t this_length = data[1];
300
+		data     += 2;
301
+		data_len -= 2;
302
+		if (tag == 9 && this_length >= 4) {
303
+			uint16_t CA_ID = (data[0] << 8) | data[1];
304
+			uint16_t CA_PID = ((data[2] & 0x1F) << 8) | data[3];
305
+			if (CA_PID == pid) {
306
+				*caid = CA_ID;
307
+				return 1;
308
+			}
309
+		}
310
+		data_len -= this_length;
311
+		data += this_length;
312
+	}
313
+	return 0;
314
+}
315
+
316
+int ts_get_emm_info_by_pid(struct ts_cat *cat, uint16_t *caid, uint16_t ca_pid) {
317
+	return find_CA_descriptor_by_pid(cat->program_info, cat->program_info_size, caid, ca_pid);
318
+}
319
+
320
+int ts_get_ecm_info_by_pid(struct ts_pmt *pmt, uint16_t *caid, uint16_t ca_pid) {
321
+	int i, result = find_CA_descriptor_by_pid(pmt->program_info, pmt->program_info_size, caid, ca_pid);
322
+	if (!result) {
323
+		for(i=0;i<pmt->streams_num;i++) {
324
+			struct ts_pmt_stream *stream = pmt->streams[i];
325
+			if (stream->ES_info) {
326
+				result = find_CA_descriptor_by_pid(stream->ES_info, stream->ES_info_size, caid, ca_pid);
327
+				if (result)
328
+					break;
329
+			}
330
+		}
331
+	}
332
+
333
+	return result;
334
+}

+ 6 - 0
tsfuncs.h View File

@@ -169,6 +169,12 @@ char *			ts_get_CA_sys_txt	(enum CA_system CA_sys);
169 169
 int				ts_get_emm_info		(struct ts_cat *cat, enum CA_system CA_sys, uint16_t *CA_id, uint16_t *CA_pid);
170 170
 int				ts_get_ecm_info		(struct ts_pmt *pmt, enum CA_system CA_sys, uint16_t *CA_id, uint16_t *CA_pid);
171 171
 
172
+int				ts_get_emm_info_by_caid	(struct ts_cat *cat, uint16_t caid, uint16_t *ca_pid);
173
+int				ts_get_ecm_info_by_caid	(struct ts_pmt *pmt, uint16_t caid, uint16_t *ca_pid);
174
+
175
+int				ts_get_emm_info_by_pid	(struct ts_cat *cat, uint16_t *caid, uint16_t ca_pid);
176
+int				ts_get_ecm_info_by_pid	(struct ts_pmt *pmt, uint16_t *caid, uint16_t ca_pid);
177
+
172 178
 // PMT
173 179
 struct ts_pmt *	ts_pmt_alloc		();
174 180
 struct ts_pmt * ts_pmt_alloc_init	(uint16_t org_network_id, uint16_t transport_stream_id);