libtsfuncs is a library for mpeg PSI parsing and generation. https://georgi.unixsol.org/programs/libtsfuncs/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tsfuncs_privsec.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <netdb.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include "tsfuncs.h"
  8. struct ts_privsec *ts_privsec_alloc() {
  9. struct ts_privsec *privsec = calloc(1, sizeof(struct ts_privsec));
  10. privsec->section_header = ts_section_data_alloc();
  11. return privsec;
  12. }
  13. void ts_privsec_free(struct ts_privsec **pprivsec) {
  14. struct ts_privsec *privsec = *pprivsec;
  15. if (privsec) {
  16. ts_section_data_free(&privsec->section_header);
  17. FREE(*pprivsec);
  18. }
  19. }
  20. struct ts_privsec *ts_privsec_push_packet(struct ts_privsec *privsec, uint8_t *ts_packet) {
  21. struct ts_header ts_header;
  22. memset(&ts_header, 0, sizeof(struct ts_header));
  23. if (ts_packet_header_parse(ts_packet, &ts_header)) {
  24. if (!privsec->ts_header.pusi)
  25. privsec->ts_header = ts_header;
  26. }
  27. if (ts_header.pusi) {
  28. struct ts_section_header section_header;
  29. memset(&section_header, 0, sizeof(struct ts_section_header));
  30. uint8_t *section_data = ts_section_header_parse(ts_packet, &privsec->ts_header, &section_header);
  31. if (!section_data) {
  32. memset(&privsec->ts_header, 0, sizeof(struct ts_header));
  33. goto OUT;
  34. }
  35. // Set correct section_header
  36. ts_section_header_parse(ts_packet, &privsec->ts_header, privsec->section_header);
  37. }
  38. if (!privsec->initialized) {
  39. ts_section_add_packet(privsec->section_header, &ts_header, ts_packet);
  40. if (privsec->section_header->initialized) {
  41. privsec->initialized = 1;
  42. }
  43. }
  44. OUT:
  45. return privsec;
  46. }
  47. void ts_privsec_dump(struct ts_privsec *privsec) {
  48. struct ts_section_header *sec = privsec->section_header;
  49. ts_section_dump(sec);
  50. char *data = ts_hex_dump(sec->data, sec->data_len, 16);
  51. ts_LOGf(" * Section data:\n%s\n", data);
  52. FREE(data);
  53. }