Browse Source

Use ts_hex_dump_buf() to avoid lots of allocations

Georgi Chorbadzhiyski 13 years ago
parent
commit
97889832ff
2 changed files with 22 additions and 16 deletions
  1. 1
    1
      libts
  2. 21
    15
      tsdecrypt.c

+ 1
- 1
libts

@@ -1 +1 @@
1
-Subproject commit 1c74afa970bfe773bc6964684f5f5f5718c1fd5c
1
+Subproject commit 9f94b2ac3464bb51402e5f65fdf4868c0d945116

+ 21
- 15
tsdecrypt.c View File

@@ -306,7 +306,11 @@ void process_pmt(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
306 306
 	}
307 307
 }
308 308
 
309
+#define dump_sz      (16)
310
+#define dump_buf_sz  (dump_sz * 6)
311
+
309 312
 void process_emm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
313
+	char dump[dump_buf_sz];
310 314
 	if (!ts->emm_pid || ts->emm_pid != pid)
311 315
 		return;
312 316
 
@@ -319,21 +323,21 @@ void process_emm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
319 323
 
320 324
 	struct ts_header *th = &ts->emm->ts_header;
321 325
 	struct ts_section_header *sec = ts->emm->section_header;
322
-	camd35_send_emm(ts->emm_caid, sec->section_data, sec->section_length + 3);
323
-	char *data = ts_hex_dump(sec->section_data, 16, 0);
324
-	ts_LOGf("EMM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d Data: %s..\n",
326
+	ts_hex_dump_buf(dump, dump_buf_sz, sec->section_data, min(dump_sz, sec->section_data_len), 0);
327
+	ts_LOGf("EMM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d ----------- Data: %s..\n",
325 328
 		ts->emm_caid,
326 329
 		th->pid,
327 330
 		sec->table_id,
328
-		sec->section_length + 3,
329
-		data);
330
-	FREE(data);
331
+		sec->section_data_len,
332
+		dump);
333
+	camd35_send_emm(ts->emm_caid, sec->section_data, sec->section_data_len);
331 334
 	ts_privsec_free(&ts->last_emm);
332 335
 	ts->last_emm = ts->emm;
333 336
 	ts->emm = ts_privsec_alloc();
334 337
 }
335 338
 
336 339
 void process_ecm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
340
+	char dump[dump_buf_sz];
337 341
 	if (!ts->ecm_pid || ts->ecm_pid != pid)
338 342
 		return;
339 343
 
@@ -346,22 +350,24 @@ void process_ecm(struct ts *ts, uint16_t pid, uint8_t *ts_packet) {
346 350
 
347 351
 	struct ts_header *th = &ts->ecm->ts_header;
348 352
 	struct ts_section_header *sec = ts->ecm->section_header;
349
-	if (!ts_privsec_is_same(ts->ecm, ts->last_ecm)) {
350
-		camd35_send_ecm(ts->service_id, ts->ecm_caid, ts->ecm_counter++, sec->section_data, sec->section_length + 3);
351
-		char *data = ts_hex_dump(sec->section_data, 16, 0);
352
-		ts_LOGf("ECM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d Data: %s..\n",
353
+	int duplicate = ts_privsec_is_same(ts->ecm, ts->last_ecm);
354
+	if (!duplicate) {
355
+		ts_hex_dump_buf(dump, dump_buf_sz, sec->section_data, min(dump_sz, sec->section_data_len), 0);
356
+		ts_LOGf("ECM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d IDX: 0x%04x Data: %s..\n",
353 357
 			ts->ecm_caid,
354 358
 			th->pid,
355 359
 			sec->table_id,
356
-			sec->section_length + 3,
357
-			data);
358
-		FREE(data);
360
+			sec->section_data_len,
361
+			ts->ecm_counter,
362
+			dump);
363
+		camd35_send_ecm(ts->service_id, ts->ecm_caid, ts->ecm_counter++, sec->section_data, sec->section_data_len);
359 364
 	} else {
360
-		ts_LOGf("ECM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d Data: --duplicate--\n",
365
+		ts_LOGf("ECM | CAID: 0x%04x PID 0x%04x Table: 0x%02x Length: %3d IDX: 0x%04x Data: -dup-\n",
361 366
 			ts->ecm_caid,
362 367
 			th->pid,
363 368
 			sec->table_id,
364
-			sec->section_length + 3);
369
+			sec->section_data_len,
370
+			ts->ecm_counter - 1);
365 371
 	}
366 372
 	ts_privsec_free(&ts->last_ecm);
367 373
 	ts->last_ecm = ts->ecm;

Loading…
Cancel
Save