|
@@ -126,8 +126,8 @@ void process_cat(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
|
126
|
126
|
}
|
127
|
127
|
}
|
128
|
128
|
|
129
|
|
-// Copied from libtsfuncs with added logic to return more than one PID
|
130
|
|
-static int find_CA_descriptor(uint8_t *data, int data_len, enum CA_system req_CA_type, uint16_t *CA_id, uint16_t *CA_pid, uint16_t *CA_pids, unsigned int *n_pids) {
|
|
129
|
+// Copied from libtsfuncs with added logic to return more than one PID and to handle both req_CA_type && forced_caid
|
|
130
|
+static int find_CA_descriptor(uint8_t *data, int data_len, enum CA_system req_CA_type, uint16_t forced_caid, uint16_t *CA_id, uint16_t *CA_pid, uint16_t *CA_pids, unsigned int *n_pids) {
|
131
|
131
|
while (data_len >= 2) {
|
132
|
132
|
uint8_t tag = data[0];
|
133
|
133
|
uint8_t this_length = data[1];
|
|
@@ -136,7 +136,13 @@ static int find_CA_descriptor(uint8_t *data, int data_len, enum CA_system req_CA
|
136
|
136
|
if (tag == 9 && this_length >= 4) {
|
137
|
137
|
uint16_t CA_ID = (data[0] << 8) | data[1];
|
138
|
138
|
uint16_t CA_PID = ((data[2] & 0x1F) << 8) | data[3];
|
139
|
|
- if (ts_get_CA_sys(CA_ID) == req_CA_type) {
|
|
139
|
+ bool ca_match = 0;
|
|
140
|
+ if (forced_caid) {
|
|
141
|
+ ca_match = forced_caid == CA_ID;
|
|
142
|
+ } else {
|
|
143
|
+ ca_match = ts_get_CA_sys(CA_ID) == req_CA_type;
|
|
144
|
+ }
|
|
145
|
+ if (ca_match) {
|
140
|
146
|
*CA_id = CA_ID;
|
141
|
147
|
*CA_pid = CA_PID;
|
142
|
148
|
if (*n_pids < MAX_ECM_PIDS) {
|
|
@@ -160,13 +166,13 @@ static int find_CA_descriptor(uint8_t *data, int data_len, enum CA_system req_CA
|
160
|
166
|
}
|
161
|
167
|
|
162
|
168
|
// Copied from libtsfuncs with added logic to return more than one PID
|
163
|
|
-int __ts_get_ecm_info(struct ts_pmt *pmt, enum CA_system req_CA_type, uint16_t *CA_id, uint16_t *CA_pid, uint16_t *CA_pids, unsigned int *n_pids) {
|
164
|
|
- int i, result = find_CA_descriptor(pmt->program_info, pmt->program_info_size, req_CA_type, CA_id, CA_pid, CA_pids, n_pids);
|
|
169
|
+int __ts_get_ecm_info(struct ts_pmt *pmt, enum CA_system req_CA_type, uint16_t forced_caid, uint16_t *CA_id, uint16_t *CA_pid, uint16_t *CA_pids, unsigned int *n_pids) {
|
|
170
|
+ int i, result = find_CA_descriptor(pmt->program_info, pmt->program_info_size, forced_caid, req_CA_type, CA_id, CA_pid, CA_pids, n_pids);
|
165
|
171
|
if (!result) {
|
166
|
172
|
for(i=0;i<pmt->streams_num;i++) {
|
167
|
173
|
struct ts_pmt_stream *stream = pmt->streams[i];
|
168
|
174
|
if (stream->ES_info) {
|
169
|
|
- result = find_CA_descriptor(stream->ES_info, stream->ES_info_size, req_CA_type, CA_id, CA_pid, CA_pids, n_pids);
|
|
175
|
+ result = find_CA_descriptor(stream->ES_info, stream->ES_info_size, req_CA_type, forced_caid, CA_id, CA_pid, CA_pids, n_pids);
|
170
|
176
|
if (result)
|
171
|
177
|
break;
|
172
|
178
|
}
|
|
@@ -206,14 +212,7 @@ void process_pmt(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
|
206
|
212
|
return;
|
207
|
213
|
|
208
|
214
|
ts->n_ecm_pids = 0;
|
209
|
|
- if (ts->forced_caid) {
|
210
|
|
- ts->ecm_caid = ts->forced_caid;
|
211
|
|
- ts_get_ecm_info_by_caid(ts->pmt, ts->ecm_caid, &ts->ecm_pid);
|
212
|
|
- ts->n_ecm_pids = 1; // TODO/FIXME: We should get the list of PIDS similar to how __ts_get_ecm_info does it
|
213
|
|
- ts->ecm_pids[0] = ts->ecm_pid;
|
214
|
|
- } else {
|
215
|
|
- __ts_get_ecm_info(ts->pmt, ts->req_CA_sys, &ts->ecm_caid, &ts->ecm_pid, &ts->ecm_pids[0], &ts->n_ecm_pids);
|
216
|
|
- }
|
|
215
|
+ __ts_get_ecm_info(ts->pmt, ts->req_CA_sys, ts->forced_caid, &ts->ecm_caid, &ts->ecm_pid, &ts->ecm_pids[0], &ts->n_ecm_pids);
|
217
|
216
|
|
218
|
217
|
if (ts->forced_ecm_pid)
|
219
|
218
|
ts_get_ecm_info_by_pid(ts->pmt, &ts->ecm_caid, ts->forced_ecm_pid);
|