mptsd reads mpegts streams from udp/multicast or http and combines them into one multiple program stream that is suitable for outputting to DVB-C modulator. Tested with Dektec DTE-3114 Quad QAM Modulator and used in production in small DVB-C networks. https://georgi.unixsol.org/programs/mptsd/
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.

pidref.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * pidref implementation
  3. * Copyright (C) 2010-2011 Unix Solutions Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  17. */
  18. #include <stdlib.h>
  19. #include "libfuncs/log.h"
  20. #include "libtsfuncs/tsfuncs.h"
  21. #include "pidref.h"
  22. PIDREF *pidref_init(int num, uint16_t base_pid) {
  23. PIDREF *ref = calloc(1, sizeof(PIDREF));
  24. ref->num = num;
  25. ref->base_pid = base_pid;
  26. ref->entries = calloc(ref->num, sizeof(PIDREF_ENTRY));
  27. return ref;
  28. }
  29. void pidref_free(PIDREF **pref) {
  30. PIDREF *ref = *pref;
  31. if (!ref)
  32. return;
  33. FREE(ref->entries);
  34. FREE(*pref);
  35. }
  36. int pidref_add(PIDREF *ref, uint16_t org_pid, uint16_t new_pid) {
  37. int i;
  38. if (!org_pid)
  39. return 0;
  40. for (i=0;i<ref->num;i++) {
  41. PIDREF_ENTRY *entry = &ref->entries[i];
  42. if (!entry->org_pid) {
  43. entry->org_pid = org_pid;
  44. entry->new_pid = new_pid;
  45. return 1;
  46. }
  47. }
  48. return 0;
  49. }
  50. int pidref_del(PIDREF *ref, uint16_t org_pid) {
  51. int i;
  52. if (!org_pid)
  53. return 0;
  54. for (i=0;i<ref->num;i++) {
  55. PIDREF_ENTRY *entry = &ref->entries[i];
  56. if (entry->org_pid == org_pid) {
  57. entry->org_pid = 0;
  58. entry->new_pid = 0;
  59. return 1;
  60. }
  61. }
  62. return 0;
  63. }
  64. uint16_t pidref_get_new_pid(PIDREF *ref, uint16_t org_pid) {
  65. int i;
  66. if (!org_pid)
  67. return 0;
  68. for (i=0;i<ref->num;i++) {
  69. PIDREF_ENTRY *entry = &ref->entries[i];
  70. if (entry->org_pid == org_pid) {
  71. return entry->new_pid;
  72. }
  73. }
  74. return 0;
  75. }
  76. int pidref_change_packet_pid(uint8_t *ts_packet, uint16_t packet_pid, PIDREF *ref) {
  77. uint16_t new_pid = pidref_get_new_pid(ref, packet_pid);
  78. if (new_pid) {
  79. ts_packet_set_pid(ts_packet, new_pid);
  80. return new_pid;
  81. }
  82. return 0;
  83. }
  84. void pidref_dump(PIDREF *ref) {
  85. int i;
  86. LOGf("pidref->base_pid = 0x%04x\n", ref->base_pid);
  87. LOGf("pidref->num = %d\n" , ref->num);
  88. LOG ("pidref->entries org_pid new_pid\n");
  89. for (i=0;i<ref->num;i++) {
  90. PIDREF_ENTRY *entry = &ref->entries[i];
  91. if (entry->org_pid)
  92. LOGf("pidref->entry[%02d] = 0x%04x 0x%04x\n", i, entry->org_pid, entry->new_pid);
  93. }
  94. }