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 2.3KB

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