Do not enter mrtg functions if mrtg is disabled.
[dvblast.git] / dvblast.h
blob40ce4c47ff3cf1bad00a51c4d364cd9fc6a40936
1 /*****************************************************************************
2 * dvblast.h
3 *****************************************************************************
4 * Copyright (C) 2004, 2008-2011 VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
7 * Andy Gatward <a.j.gatward@reading.ac.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <netdb.h>
25 #include <sys/socket.h>
27 #define HAVE_CLOCK_NANOSLEEP
28 #define HAVE_ICONV
30 #define DEFAULT_PORT 3001
31 #define TS_SIZE 188
32 #define MAX_PIDS 8192
33 #define DEFAULT_IPV4_MTU 1500
34 #define DEFAULT_IPV6_MTU 1280
35 #define PADDING_PID 8191
36 #define WATCHDOG_WAIT 10000000LL
37 #define MAX_ERRORS 1000
38 #define DEFAULT_VERBOSITY 4
39 #define MAX_POLL_TIMEOUT 100000 /* 100 ms */
40 #define DEFAULT_OUTPUT_LATENCY 200000 /* 200 ms */
41 #define DEFAULT_MAX_RETENTION 40000 /* 40 ms */
42 #define MAX_EIT_RETENTION 500000 /* 500 ms */
43 #define DEFAULT_FRONTEND_TIMEOUT 30000000 /* 30 s */
44 #define EXIT_STATUS_FRONTEND_TIMEOUT 100
46 /*****************************************************************************
47 * Output configuration flags (for output_t -> i_config) - bit values
48 * Bit 0 : Set for watch mode
49 * Bit 1 : Set output still present
50 * Bit 2 : Set if output is valid (replaces m_addr != 0 tests)
51 * Bit 3 : Set for UDP, otherwise use RTP if a network stream
52 * Bit 4 : Set for file / FIFO output, unset for network (future use)
53 * Bit 5 : Set if DVB conformance tables are inserted
54 * Bit 6 : Set if DVB EIT schedule tables are forwarded
55 * Bit 7 : Set if EMM pids and CAT are forwarded
56 * Bit 8 : Set if ECM pids are forwarded
57 *****************************************************************************/
59 #define OUTPUT_WATCH 0x01
60 #define OUTPUT_STILL_PRESENT 0x02
61 #define OUTPUT_VALID 0x04
62 #define OUTPUT_UDP 0x08
63 #define OUTPUT_FILE 0x10
64 #define OUTPUT_DVB 0x20
65 #define OUTPUT_EPG 0x40
66 #define OUTPUT_EMM (1 << 7)
67 #define OUTPUT_ECM (1 << 8)
69 typedef int64_t mtime_t;
71 typedef struct block_t
73 uint8_t p_ts[TS_SIZE];
74 int i_refcount;
75 mtime_t i_dts;
76 struct block_t *p_next;
77 } block_t;
79 typedef struct packet_t packet_t;
81 typedef struct output_config_t
83 /* identity */
84 int i_family;
85 struct sockaddr_storage connect_addr;
86 struct sockaddr_storage bind_addr;
87 int i_if_index_v6;
89 /* common config */
90 char *psz_displayname;
91 uint64_t i_config;
93 /* output config */
94 char *psz_service_name;
95 char *psz_service_provider;
96 uint8_t pi_ssrc[4];
97 mtime_t i_output_latency, i_max_retention;
98 int i_ttl;
99 uint8_t i_tos;
100 int i_mtu;
102 /* demux config */
103 int i_tsid;
104 uint16_t i_sid; /* 0 if raw mode */
105 uint16_t *pi_pids;
106 int i_nb_pids;
107 } output_config_t;
109 typedef struct output_t
111 output_config_t config;
113 /* output */
114 int i_handle;
115 packet_t *p_packets, *p_last_packet;
116 uint16_t i_seqnum;
117 mtime_t i_ref_timestamp;
118 mtime_t i_ref_wallclock;
120 /* demux */
121 int i_nb_errors;
122 mtime_t i_last_error;
123 uint8_t *p_pat_section;
124 uint8_t i_pat_version, i_pat_cc;
125 uint8_t *p_pmt_section;
126 uint8_t i_pmt_version, i_pmt_cc;
127 uint8_t *p_nit_section;
128 uint8_t i_nit_version, i_nit_cc;
129 uint8_t *p_sdt_section;
130 uint8_t i_sdt_version, i_sdt_cc;
131 block_t *p_eit_ts_buffer;
132 uint8_t i_eit_ts_buffer_offset, i_eit_cc;
133 uint16_t i_tsid;
134 } output_t;
136 typedef struct ts_pid_info {
137 mtime_t i_first_packet_ts; /* Time of the first seen packet */
138 mtime_t i_last_packet_ts; /* Time of the last seen packet */
139 unsigned long i_packets; /* How much packets have been seen */
140 unsigned long i_cc_errors; /* Countinuity counter errors */
141 unsigned long i_transport_errors; /* Transport errors */
142 unsigned long i_bytes_per_sec; /* How much bytes were process last second */
143 uint8_t i_scrambling; /* Scrambling bits from the last ts packet */
144 /* 0 = Not scrambled
145 1 = Reserved for future use
146 2 = Scrambled with even key
147 3 = Scrambled with odd key */
148 } ts_pid_info_t;
150 extern int i_syslog;
151 extern int i_verbose;
152 extern output_t **pp_outputs;
153 extern int i_nb_outputs;
154 extern output_t output_dup;
155 extern char *psz_srv_socket;
156 extern int i_comm_fd;
157 extern int i_adapter;
158 extern int i_fenum;
159 extern int i_frequency;
160 extern int i_srate;
161 extern int i_satnum;
162 extern int i_fec;
163 extern int i_rolloff;
164 extern int i_voltage;
165 extern int b_tone;
166 extern int i_bandwidth;
167 extern int i_inversion;
168 extern char *psz_modulation;
169 extern int i_pilot;
170 extern int i_fec_lp;
171 extern int i_guard;
172 extern int i_transmission;
173 extern int i_hierarchy;
174 extern mtime_t i_frontend_timeout_duration;
175 extern mtime_t i_quit_timeout;
176 extern mtime_t i_quit_timeout_duration;
177 extern int b_budget_mode;
178 extern int b_any_type;
179 extern int b_select_pmts;
180 extern int b_random_tsid;
181 extern uint16_t i_network_id;
182 extern uint8_t *p_network_name;
183 extern size_t i_network_name_size;
184 extern mtime_t i_wallclock;
185 extern volatile int b_conf_reload;
186 extern volatile int b_exit_now;
187 extern int i_comm_fd;
188 extern char *psz_udp_src;
189 extern int i_asi_adapter;
190 extern const char *psz_native_charset;
191 extern const char *psz_dvb_charset;
192 extern enum print_type_t i_print_type;
194 extern void (*pf_Open)( void );
195 extern block_t * (*pf_Read)( mtime_t i_poll_timeout );
196 extern void (*pf_Reset)( void );
197 extern int (*pf_SetFilter)( uint16_t i_pid );
198 extern void (*pf_UnsetFilter)( int i_fd, uint16_t i_pid );
200 /*****************************************************************************
201 * Prototypes
202 *****************************************************************************/
204 void config_Init( output_config_t *p_config );
205 void config_Free( output_config_t *p_config );
206 bool config_ParseHost( output_config_t *p_config, char *psz_string );
208 /* Connect/Disconnect from syslogd */
209 void msg_Connect( const char *ident );
210 void msg_Disconnect( void );
212 /* */
213 __attribute__ ((format(printf, 2, 3))) void msg_Info( void *_unused, const char *psz_format, ... );
214 __attribute__ ((format(printf, 2, 3))) void msg_Err( void *_unused, const char *psz_format, ... );
215 __attribute__ ((format(printf, 2, 3))) void msg_Warn( void *_unused, const char *psz_format, ... );
216 __attribute__ ((format(printf, 2, 3))) void msg_Dbg( void *_unused, const char *psz_format, ... );
217 __attribute__ ((format(printf, 2, 3))) void msg_Raw( void *_unused, const char *psz_format, ... );
219 /* */
220 bool streq(char *a, char *b);
221 char * xstrdup(char *str);
222 mtime_t mdate( void );
223 void msleep( mtime_t delay );
224 void hexDump( uint8_t *p_data, uint32_t i_len );
225 struct addrinfo *ParseNodeService( char *_psz_string, char **ppsz_end,
226 uint16_t i_default_port );
228 uint8_t *psi_pack_section( uint8_t *p_sections, unsigned int *pi_size );
229 uint8_t *psi_pack_sections( uint8_t **pp_sections, unsigned int *pi_size );
230 uint8_t **psi_unpack_sections( uint8_t *p_flat_sections, unsigned int i_size );
232 void dvb_Open( void );
233 void dvb_Reset( void );
234 block_t * dvb_Read( mtime_t i_poll_timeout );
235 int dvb_SetFilter( uint16_t i_pid );
236 void dvb_UnsetFilter( int i_fd, uint16_t i_pid );
237 uint8_t dvb_FrontendStatus( uint8_t *p_answer, ssize_t *pi_size );
239 void udp_Open( void );
240 block_t * udp_Read( mtime_t i_poll_timeout );
241 void udp_Reset( void );
242 int udp_SetFilter( uint16_t i_pid );
243 void udp_UnsetFilter( int i_fd, uint16_t i_pid );
245 void asi_Open( void );
246 block_t * asi_Read( mtime_t i_poll_timeout );
247 void asi_Reset( void );
248 int asi_SetFilter( uint16_t i_pid );
249 void asi_UnsetFilter( int i_fd, uint16_t i_pid );
251 void demux_Open( void );
252 void demux_Run( block_t *p_ts );
253 void demux_Change( output_t *p_output, const output_config_t *p_config );
254 void demux_ResendCAPMTs( void );
255 bool demux_PIDIsSelected( uint16_t i_pid );
256 char *demux_Iconv(void *_unused, const char *psz_encoding,
257 char *p_string, size_t i_length);
258 void demux_Close( void );
260 uint8_t *demux_get_current_packed_PAT( unsigned int *pi_pack_size );
261 uint8_t *demux_get_current_packed_CAT( unsigned int *pi_pack_size );
262 uint8_t *demux_get_current_packed_NIT( unsigned int *pi_pack_size );
263 uint8_t *demux_get_current_packed_SDT( unsigned int *pi_pack_size );
264 uint8_t *demux_get_packed_PMT( uint16_t service_id, unsigned int *pi_pack_size );
265 void demux_get_PID_info( uint16_t i_pid, uint8_t *p_data );
266 void demux_get_PIDS_info( uint8_t *p_data );
268 output_t *output_Create( const output_config_t *p_config );
269 int output_Init( output_t *p_output, const output_config_t *p_config );
270 void output_Close( output_t *p_output );
271 void output_Put( output_t *p_output, block_t *p_block );
272 mtime_t output_Send( void );
273 output_t *output_Find( const output_config_t *p_config );
274 void output_Change( output_t *p_output, const output_config_t *p_config );
275 void outputs_Close( int i_num_outputs );
277 void comm_Open( void );
278 void comm_Read( void );
280 /*****************************************************************************
281 * block_New
282 *****************************************************************************/
283 static inline block_t *block_New( void )
285 block_t *p_block = malloc(sizeof(block_t));
286 p_block->p_next = NULL;
287 p_block->i_refcount = 1;
288 return p_block;
291 /*****************************************************************************
292 * block_Delete
293 *****************************************************************************/
294 static inline void block_Delete( block_t *p_block )
296 free( p_block );
299 /*****************************************************************************
300 * block_DeleteChain
301 *****************************************************************************/
302 static inline void block_DeleteChain( block_t *p_block )
304 while ( p_block != NULL )
306 block_t *p_next = p_block->p_next;
307 free( p_block );
308 p_block = p_next;