libtsfuncs is a library for mpeg PSI parsing and generation. https://georgi.unixsol.org/programs/libtsfuncs/

tstest.c 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * libtsfuncs test program
  3. * Copyright (C) 2010-2011 Unix Solutions Ltd.
  4. *
  5. * Released under MIT license.
  6. * See LICENSE-MIT.txt for license terms.
  7. */
  8. #include "tsfuncs.h"
  9. #define NOW 1234567890
  10. #define NOW2 1000000000
  11. void ts_pat_test() {
  12. struct ts_pat *pat = ts_pat_alloc_init(0x7878);
  13. ts_pat_dump(pat);
  14. ts_pat_add_program(pat, 1, 0x100);
  15. ts_pat_add_program(pat, 2, 0x100);
  16. ts_pat_add_program(pat, 3, 0x100);
  17. ts_pat_dump(pat);
  18. ts_pat_del_program(pat, 2);
  19. ts_pat_dump(pat);
  20. ts_pat_del_program(pat, 3);
  21. ts_pat_dump(pat);
  22. int i;
  23. for (i=0;i<10;i++) {
  24. ts_pat_add_program(pat, i+10, (i+5)*10);
  25. }
  26. ts_pat_dump(pat);
  27. ts_pat_free(&pat);
  28. }
  29. void ts_tdt_test() {
  30. struct ts_tdt *tdt = ts_tdt_alloc_init(NOW);
  31. ts_tdt_dump(tdt);
  32. ts_tdt_set_time(tdt, NOW2);
  33. ts_tdt_dump(tdt);
  34. ts_tdt_free(&tdt);
  35. }
  36. void ts_tot_test() {
  37. struct ts_tdt *tot;
  38. tot = ts_tot_alloc_init(NOW);
  39. ts_tdt_dump(tot);
  40. ts_tdt_free(&tot);
  41. tot = ts_tot_alloc_init(NOW);
  42. ts_tot_set_localtime_offset_sofia(tot, NOW);
  43. ts_tdt_dump(tot);
  44. ts_tdt_free(&tot);
  45. tot = ts_tot_alloc_init(NOW2);
  46. ts_tot_set_localtime_offset_sofia(tot, NOW2);
  47. ts_tdt_dump(tot);
  48. ts_tdt_free(&tot);
  49. }
  50. int ts_sdt_test() {
  51. struct ts_sdt *sdt = ts_sdt_alloc_init(1, 2);
  52. ts_sdt_add_service_descriptor(sdt, 1007, 1, "BULSATCOM", "bTV");
  53. ts_sdt_dump(sdt);
  54. int i;
  55. for (i=0;i<25;i++) {
  56. ts_sdt_add_service_descriptor(sdt, 9, 0, "PROVIDER", "SERVICE33333333333333333333333333333333333333333333333333333333333333");
  57. ts_sdt_add_service_descriptor(sdt, 13, 0, "PROddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddVIDER", "SERVICE");
  58. ts_sdt_add_service_descriptor(sdt, 7, 0, "PROVIDER", "SERVICE");
  59. }
  60. ts_sdt_dump(sdt);
  61. // write(1, sdt->section_header->packet_data, sdt->section_header->num_packets * 188);
  62. ts_sdt_free(&sdt);
  63. return 0;
  64. }
  65. void ts_eit_test1(struct ts_eit *eit) { // Exactly one TS packet (188 bytes)
  66. //int ts_eit_add_short_event_descriptor(struct ts_eit *eit, uint16_t event_id, uint8_t running, time_t start_time, int duration_sec, char *event_name, char *event_short_descr) {
  67. ts_eit_add_short_event_descriptor(eit, 4, 1, NOW, 3600,
  68. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  69. "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy****");
  70. }
  71. void ts_eit_test2(struct ts_eit *eit) { // One TS packet + 2 bytes (2 bytes of the CRC are in the next packet
  72. ts_eit_add_short_event_descriptor(eit, 4, 1, NOW, 3600,
  73. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  74. "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy**");
  75. }
  76. void ts_eit_test3(struct ts_eit *eit) { // Test 4096 PSI packet
  77. int i;
  78. for (i=0;i<15;i++) {
  79. // Maximum descriptor size, 255 bytes
  80. if (ts_eit_add_short_event_descriptor(eit, 4, 1, NOW, 3600, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") != 1) {
  81. break;
  82. }
  83. }
  84. ts_eit_add_short_event_descriptor(eit, 4, 1, NOW, 3600, "00000000000000000000000", "1111111111111111111111111111111");
  85. }
  86. void ts_eit_test4(struct ts_eit *eit) { // Test almost full PSI packet on the TS packet boundary
  87. int i;
  88. for (i=0;i<15;i++) {
  89. // Maximum descriptor size, 255 bytes
  90. if (ts_eit_add_short_event_descriptor(eit, 4, 1, NOW, 3600, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") != 1) {
  91. break;
  92. }
  93. }
  94. ts_eit_add_short_event_descriptor(eit, 4, 1, NOW, 3600, "aaaaaaaaBBBB", NULL);
  95. }
  96. void ts_eit_test() {
  97. struct ts_eit *eit;
  98. eit = ts_eit_alloc_init(1, 2, 3, 1, 0, 0);
  99. ts_eit_test1(eit);
  100. ts_eit_dump(eit);
  101. ts_eit_free(&eit);
  102. eit = ts_eit_alloc_init(1, 2, 3, 1, 0, 0);
  103. ts_eit_test2(eit);
  104. ts_eit_dump(eit);
  105. ts_eit_free(&eit);
  106. eit = ts_eit_alloc_init(1, 2, 3, 1, 0, 0);
  107. ts_eit_test3(eit);
  108. ts_eit_dump(eit);
  109. ts_eit_free(&eit);
  110. eit = ts_eit_alloc_init(1, 2, 3, 1, 0, 0);
  111. ts_eit_test4(eit);
  112. ts_eit_dump(eit);
  113. ts_eit_free(&eit);
  114. // write(1, eit->section_header->packet_data, eit->section_header->num_packets * TS_PACKET_SIZE);
  115. }
  116. int main() {
  117. ts_pat_test();
  118. ts_tdt_test();
  119. ts_tot_test();
  120. ts_sdt_test();
  121. ts_eit_test();
  122. return 0;
  123. }