|
@@ -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
|
+}
|