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.

privsec.c 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_clear(struct ts_privsec *privsec) {
  14. if (!privsec)
  15. return;
  16. // save
  17. struct ts_section_header *section_header = privsec->section_header;
  18. // clear
  19. ts_section_data_clear(section_header);
  20. memset(privsec, 0, sizeof(struct ts_privsec));
  21. // restore
  22. privsec->section_header = section_header;
  23. }
  24. void ts_privsec_free(struct ts_privsec **pprivsec) {
  25. struct ts_privsec *privsec = *pprivsec;
  26. if (privsec) {
  27. ts_section_data_free(&privsec->section_header);
  28. FREE(*pprivsec);
  29. }
  30. }
  31. void ts_privsec_copy(struct ts_privsec *src, struct ts_privsec *dst) {
  32. if (!src || !dst)
  33. return;
  34. dst->ts_header = src->ts_header;
  35. dst->initialized = src->initialized;
  36. ts_section_data_copy(src->section_header, dst->section_header);
  37. }
  38. struct ts_privsec *ts_privsec_push_packet(struct ts_privsec *privsec, uint8_t *ts_packet) {
  39. struct ts_header ts_header;
  40. memset(&ts_header, 0, sizeof(struct ts_header));
  41. if (ts_packet_header_parse(ts_packet, &ts_header)) {
  42. if (!privsec->ts_header.pusi)
  43. privsec->ts_header = ts_header;
  44. }
  45. if (ts_header.pusi) {
  46. struct ts_section_header section_header;
  47. memset(&section_header, 0, sizeof(struct ts_section_header));
  48. uint8_t *section_data = ts_section_header_parse(ts_packet, &privsec->ts_header, &section_header);
  49. if (!section_data) {
  50. memset(&privsec->ts_header, 0, sizeof(struct ts_header));
  51. goto OUT;
  52. }
  53. // Set correct section_header
  54. ts_section_header_parse(ts_packet, &privsec->ts_header, privsec->section_header);
  55. }
  56. if (!privsec->initialized) {
  57. ts_section_add_packet(privsec->section_header, &ts_header, ts_packet);
  58. if (privsec->section_header->initialized) {
  59. privsec->initialized = 1;
  60. }
  61. }
  62. OUT:
  63. return privsec;
  64. }
  65. int ts_privsec_is_same(struct ts_privsec *p1, struct ts_privsec *p2) {
  66. if (p1 == p2) return 1; // Same
  67. if ((!p1 && p2) || (p1 && !p2)) return 0; // Not same (one is NULL)
  68. if (p1->section_header->section_length != p1->section_header->section_length) return 0; // Not same
  69. return memcmp(p1->section_header->section_data, p2->section_header->section_data, p1->section_header->section_length) == 0;
  70. }
  71. void ts_privsec_dump(struct ts_privsec *privsec) {
  72. struct ts_section_header *sec = privsec->section_header;
  73. ts_section_dump(sec);
  74. char *data = ts_hex_dump(sec->data, sec->data_len, 16);
  75. ts_LOGf(" * Section data:\n%s\n", data);
  76. FREE(data);
  77. }