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.

data.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * mptsd data header file
  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. #ifndef DATA_H
  19. #define DATA_H
  20. /* How much to wait for connection to be established with channel source (miliseconds) */
  21. #define PROXY_CONNECT_TIMEOUT 1000
  22. /* Seconds to sleep between retries (miliseconds) */
  23. #define PROXY_RETRY_TIMEOUT 1000
  24. /* 7 * 188 */
  25. #define FRAME_PACKET_SIZE 1316
  26. #define RTP_HEADER_SIZE 12
  27. #include "libfuncs/libfuncs.h"
  28. #include "libtsfuncs/tsdata.h"
  29. #include "pidref.h"
  30. typedef enum { udp_sock, tcp_sock } channel_source;
  31. typedef struct {
  32. channel_source sproto;
  33. char *proto;
  34. char *host;
  35. char *path;
  36. unsigned int port;
  37. unsigned int rtp;
  38. } CHANSRC;
  39. #define MAX_CHANNEL_SOURCES 8
  40. typedef struct {
  41. uint16_t event_id;
  42. time_t start;
  43. int duration;
  44. char * event;
  45. char * short_desc;
  46. char * long_desc;
  47. } EPG_ENTRY;
  48. typedef struct {
  49. /* Config */
  50. int base_pid;
  51. int service_id;
  52. int pmt_pid;
  53. int radio;
  54. int lcn;
  55. int lcn_visible;
  56. char * id;
  57. char * name;
  58. /* Sources */
  59. char * source; /* Full source url */
  60. char * sources[MAX_CHANNEL_SOURCES];
  61. uint8_t num_src;
  62. uint8_t curr_src;
  63. int worktime_start;
  64. int worktime_end;
  65. /* EPG */
  66. uint8_t epg_version:5;
  67. EPG_ENTRY * epg_now;
  68. EPG_ENTRY * epg_next;
  69. struct ts_eit * eit_now;
  70. struct ts_eit * eit_next;
  71. } CHANNEL;
  72. typedef struct {
  73. uint64_t pcr;
  74. uint64_t last_pcr;
  75. int bytes;
  76. int ts_packets_per_output_bitrate;
  77. } PCR;
  78. typedef struct {
  79. PIDREF *pidref; /* Rewritten pids list */
  80. uint16_t nit_pid; /* Pid of the NIT, default 0x10 */
  81. uint16_t pmt_pid; /* Pid of the original PMT, used to replace PMT */
  82. uint16_t pcr_pid; /* PCR pid */
  83. struct ts_pat *pat; /* The PAT */
  84. struct ts_pmt *pmt; /* The PMT */
  85. uint64_t input_pcr; // Latest PCR entered into input buffer
  86. uint8_t pid_pat_cont:4;
  87. uint8_t pid_pmt_cont:4;
  88. struct ts_pat *pat_rewritten; /* The rewritten PAT */
  89. struct ts_pmt *pmt_rewritten; /* The rewritten PMT */
  90. struct ts_pat *last_pat; /* The last incoming PAT */
  91. struct ts_pmt *last_pmt; /* The last incoming PMT */
  92. } INPUT_STREAM;
  93. typedef struct {
  94. char *name;
  95. CHANNEL *channel;
  96. int sock; /* Server socket */
  97. struct sockaddr_in src_sockname;
  98. int reconnect:1, /* Set to 1 to force proxy reconnect */
  99. connected:1, /* It's set to 1 when proxy is connected and serving clients */
  100. insert_eit:1, /* When set to 1 input adds EIT table into stream (if there is info) */
  101. working:1, /* Set to 1 if the input is in worktime */
  102. dienow:1, /* Stop serving clients and exit now */
  103. freechannel:1; /* Free channel data on object free (this is used in chanconf) */
  104. int cookie; /* Used in chanconf to determine if the restreamer is alrady checked */
  105. int ifd;
  106. pthread_t thread;
  107. uint16_t output_pcr_pid;
  108. uint64_t output_last_pcr; // The PCR before latest outputed
  109. uint64_t output_pcr; // Latest outputed PCR
  110. int output_pcr_packets_needed; // Based on selected output rate how much packets should be between output_pcr and output_last_pcr
  111. int outputed_packets; // How much packets have been sent. This is reset on every PCR and incremented on every sent packet (every input and output padding)
  112. int disabled; /* Input is disabled, no data is fed to output buffers */
  113. int input_ready; /* Set to 1 from INPUT thread when input is ready to be mixed in output */
  114. CBUF *buf; // Input buffer */
  115. INPUT_STREAM stream;
  116. } INPUT;
  117. typedef enum {
  118. obuf_empty = 0, // Buffer is empty and can be used by mix thread
  119. obuf_filling = 1, // Buffer is being filled by mix thread
  120. obuf_full = 2, // Buffer is filled and can be used by write thread
  121. obuf_emptying = 3, // Buffer is being emptyed by write thread
  122. } OBUF_STATUS;
  123. typedef struct {
  124. uint8_t * buf;
  125. int size; // Output buffer size (must be size % 1316 == 0)
  126. int written;
  127. OBUF_STATUS status;
  128. } OBUF;
  129. typedef struct {
  130. struct in_addr out_host;
  131. int out_port;
  132. int out_sock; /* The udp socket */
  133. int ofd;
  134. int dienow; /* Instruct output to die */
  135. pthread_t psi_thread;
  136. pthread_t mix_thread;
  137. pthread_t write_thread;
  138. CBUF *psibuf; // Input buffer */
  139. unsigned int obuf_ms; // How much miliseconds of data output buffer holds
  140. OBUF obuf[2]; // Output buffers
  141. double output_bitrate; // Output bitrate (bps)
  142. uint64_t traffic;
  143. uint64_t traffic_period;
  144. uint64_t padding_period;
  145. uint8_t pid_pat_cont:4;
  146. uint8_t pid_nit_cont:4;
  147. uint8_t pid_sdt_cont:4;
  148. uint8_t pid_eit_cont:4;
  149. uint8_t pid_tdt_cont:4;
  150. struct ts_pat *pat;
  151. struct timeval pat_ts;
  152. struct ts_sdt *sdt;
  153. struct timeval sdt_ts;
  154. struct ts_nit *nit;
  155. struct timeval nit_ts;
  156. struct ts_tdt *tdt;
  157. struct timeval tdt_ts;
  158. struct ts_tdt *tot;
  159. struct timeval tot_ts;
  160. struct timeval eit_ts;
  161. uint64_t last_org_pcr[8193]; // Last PCR value indexed by PID x
  162. uint64_t last_pcr[8193]; // Last PCR value indexed by PID x
  163. uint64_t last_traffic[8193]; // Last traffic when PCR with PID x was seen
  164. } OUTPUT;
  165. typedef struct {
  166. char *freq;
  167. char *modulation;
  168. char *symbol_rate;
  169. uint16_t ts_id;
  170. uint32_t _freq;
  171. uint8_t _modulation;
  172. uint32_t _symbol_rate;
  173. } NIT;
  174. EPG_ENTRY * epg_new (time_t start, int duration, char *encoding, char *event, char *short_desc, char *long_desc);
  175. void epg_free (EPG_ENTRY **e);
  176. int epg_changed (EPG_ENTRY *a, EPG_ENTRY *b);
  177. CHANNEL * channel_new (int service_id, int is_radio, char *id, char *name, char *source, int lcn, int is_lcn_visible);
  178. void channel_free (CHANNEL **c);
  179. void channel_free_epg(CHANNEL *c);
  180. channel_source get_sproto(char *url);
  181. int is_rtp(char *url);
  182. CHANSRC * chansrc_init (char *url);
  183. void chansrc_free (CHANSRC **url);
  184. void chansrc_add (CHANNEL *c, char *src);
  185. void chansrc_next (CHANNEL *c);
  186. void chansrc_set (CHANNEL *c, uint8_t src_id);
  187. INPUT * input_new (const char *name, CHANNEL *channel);
  188. void input_free (INPUT **input);
  189. void input_stream_reset (INPUT *input);
  190. OUTPUT * output_new ();
  191. void output_free (OUTPUT **output);
  192. void output_open_file (OUTPUT *o);
  193. void output_buffer_alloc (OUTPUT *o, double output_bitrate);
  194. void obuf_reset (OBUF *ob);
  195. NIT * nit_new (uint16_t ts_id, char *freq, char *modulation, char *symbol_rate);
  196. void nit_free (NIT **nit);
  197. void proxy_log (INPUT *r, char *msg);
  198. void proxy_close (LIST *inputs, INPUT **input);
  199. #endif