-
Notifications
You must be signed in to change notification settings - Fork 41
/
data.h
264 lines (208 loc) · 7.23 KB
/
data.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* mptsd data header file
* Copyright (C) 2010-2011 Unix Solutions Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*/
#ifndef DATA_H
#define DATA_H
/* How much to wait for connection to be established with channel source (miliseconds) */
#define PROXY_CONNECT_TIMEOUT 1000
/* Seconds to sleep between retries (miliseconds) */
#define PROXY_RETRY_TIMEOUT 1000
/* 7 * 188 */
#define FRAME_PACKET_SIZE 1316
#define RTP_HEADER_SIZE 12
#include "libfuncs/libfuncs.h"
#include "libtsfuncs/tsdata.h"
#include "pidref.h"
typedef enum { udp_sock, tcp_sock } channel_source;
typedef struct {
channel_source sproto;
char *proto;
char *host;
char *path;
unsigned int port;
unsigned int rtp;
} CHANSRC;
#define MAX_CHANNEL_SOURCES 8
typedef struct {
uint16_t event_id;
time_t start;
int duration;
char * event;
char * short_desc;
char * long_desc;
} EPG_ENTRY;
typedef struct {
/* Config */
int index;
int base_pid;
int service_id;
int pmt_pid;
int radio;
int lcn;
int lcn_visible;
char * id;
char * name;
int eit_mode; /* 0 = ignore EIT data from input
1 = forward EIT data for the configured service, ignore any other EIT data
*/
/* Sources */
char * source; /* Full source url */
char * sources[MAX_CHANNEL_SOURCES];
uint8_t num_src;
uint8_t curr_src;
int worktime_start;
int worktime_end;
/* EPG */
uint8_t epg_version:5;
EPG_ENTRY * epg_now;
EPG_ENTRY * epg_next;
struct ts_eit * eit_now;
struct ts_eit * eit_next;
} CHANNEL;
typedef struct {
uint64_t pcr;
uint64_t last_pcr;
int bytes;
int ts_packets_per_output_bitrate;
} PCR;
typedef struct {
PIDREF *pidref; /* Rewritten pids list */
uint16_t nit_pid; /* Pid of the NIT, default 0x10 */
uint16_t pmt_pid; /* Pid of the original PMT, used to replace PMT */
uint16_t pcr_pid; /* PCR pid */
struct ts_pat *pat; /* The PAT */
struct ts_pmt *pmt; /* The PMT */
struct ts_eit *eit; /* The EIT */
uint64_t input_pcr; // Latest PCR entered into input buffer
uint8_t pid_pat_cont:4;
uint8_t pid_pmt_cont:4;
uint8_t pid_eit_cont : 4;
struct ts_pat *pat_rewritten; /* The rewritten PAT */
struct ts_pmt *pmt_rewritten; /* The rewritten PMT */
struct ts_eit *eit_rewritten; /* The rewritten EIT */
struct ts_pat *last_pat; /* The last incoming PAT */
struct ts_pmt *last_pmt; /* The last incoming PMT */
} INPUT_STREAM;
typedef struct {
char *name;
CHANNEL *channel;
int sock; /* Server socket */
struct sockaddr_in src_sockname;
int reconnect:1, /* Set to 1 to force proxy reconnect */
connected:1, /* It's set to 1 when proxy is connected and serving clients */
insert_eit:1, /* When set to 1 input adds EIT table into stream (if there is info) */
working:1, /* Set to 1 if the input is in worktime */
dienow:1, /* Stop serving clients and exit now */
freechannel:1; /* Free channel data on object free (this is used in chanconf) */
int cookie; /* Used in chanconf to determine if the restreamer is alrady checked */
int ifd;
pthread_t thread;
uint16_t output_pcr_pid;
uint64_t output_last_pcr; // The PCR before latest outputed
uint64_t output_pcr; // Latest outputed PCR
int output_pcr_packets_needed; // Based on selected output rate how much packets should be between output_pcr and output_last_pcr
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)
int disabled; /* Input is disabled, no data is fed to output buffers */
int input_ready; /* Set to 1 from INPUT thread when input is ready to be mixed in output */
CBUF *buf; // Input buffer */
INPUT_STREAM stream;
} INPUT;
typedef enum {
obuf_empty = 0, // Buffer is empty and can be used by mix thread
obuf_filling = 1, // Buffer is being filled by mix thread
obuf_full = 2, // Buffer is filled and can be used by write thread
obuf_emptying = 3, // Buffer is being emptyed by write thread
} OBUF_STATUS;
typedef struct {
uint8_t * buf;
int size; // Output buffer size (must be size % 1316 == 0)
int written;
OBUF_STATUS status;
} OBUF;
typedef struct {
struct in_addr out_host;
int out_port;
int out_sock; /* The udp socket */
int ofd;
int dienow; /* Instruct output to die */
pthread_t psi_thread;
pthread_t mix_thread;
pthread_t write_thread;
CBUF *psibuf; // Input buffer */
unsigned int obuf_ms; // How much miliseconds of data output buffer holds
OBUF obuf[2]; // Output buffers
double output_bitrate; // Output bitrate (bps)
uint64_t traffic;
uint64_t traffic_period;
uint64_t padding_period;
uint8_t pid_pat_cont:4;
uint8_t pid_nit_cont:4;
uint8_t pid_sdt_cont:4;
uint8_t pid_eit_cont:4;
uint8_t pid_tdt_cont:4;
struct ts_pat *pat;
struct timeval pat_ts;
struct ts_sdt *sdt;
struct timeval sdt_ts;
struct ts_nit *nit;
struct timeval nit_ts;
struct ts_tdt *tdt;
struct timeval tdt_ts;
struct ts_tdt *tot;
struct timeval tot_ts;
struct timeval eit_ts;
uint64_t last_org_pcr[8193]; // Last PCR value indexed by PID x
uint64_t last_pcr[8193]; // Last PCR value indexed by PID x
uint64_t last_traffic[8193]; // Last traffic when PCR with PID x was seen
uint16_t rtp_sequence_number; // RTP sequence number
uint32_t rtp_ssrc; // use RTP is != 0
} OUTPUT;
typedef struct {
char *freq;
char *modulation;
char *symbol_rate;
uint16_t ts_id;
uint32_t _freq;
uint8_t _modulation;
uint32_t _symbol_rate;
} NIT;
EPG_ENTRY * epg_new (time_t start, int duration, char *encoding, char *event, char *short_desc, char *long_desc);
void epg_free (EPG_ENTRY **e);
int epg_changed (EPG_ENTRY *a, EPG_ENTRY *b);
CHANNEL * channel_new (int service_id, int is_radio, const char *id, const char *name, int eit_mode, const char *source, int channel_index, int lcn, int is_lcn_visible);
void channel_free (CHANNEL **c);
void channel_free_epg(CHANNEL *c);
channel_source get_sproto(char *url);
int is_rtp(char *url);
CHANSRC * chansrc_init (char *url);
void chansrc_free (CHANSRC **url);
void chansrc_add (CHANNEL *c, const char *src);
void chansrc_next (CHANNEL *c);
void chansrc_set (CHANNEL *c, uint8_t src_id);
INPUT * input_new (const char *name, CHANNEL *channel);
void input_free (INPUT **input);
void input_stream_reset (INPUT *input);
OUTPUT * output_new ();
void output_free (OUTPUT **output);
void output_open_file (char *filename, OUTPUT *o);
void output_buffer_alloc (OUTPUT *o, double output_bitrate);
void obuf_reset (OBUF *ob);
NIT * nit_new (uint16_t ts_id, char *freq, char *modulation, char *symbol_rate);
void nit_free (NIT **nit);
void proxy_log (INPUT *r, char *msg);
void proxy_close (LIST *inputs, INPUT **input);
#endif