1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004, 2008-2009 VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Andy Gatward <a.j.gatward@reading.ac.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include <sys/socket.h>
28 #define HAVE_CLOCK_NANOSLEEP
31 #define DEFAULT_PORT 3001
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 *****************************************************************************/
57 #define OUTPUT_WATCH 0x01
58 #define OUTPUT_STILL_PRESENT 0x02
59 #define OUTPUT_VALID 0x04
60 #define OUTPUT_UDP 0x08
61 #define OUTPUT_FILE 0x10
62 #define OUTPUT_DVB 0x20
63 #define OUTPUT_EPG 0x40
65 typedef int64_t mtime_t
;
67 typedef struct block_t
69 uint8_t p_ts
[TS_SIZE
];
72 struct block_t
*p_next
;
75 typedef struct packet_t packet_t
;
77 typedef struct output_config_t
81 struct sockaddr_storage connect_addr
;
82 struct sockaddr_storage bind_addr
;
86 char *psz_displayname
;
91 mtime_t i_output_latency
, i_max_retention
;
98 uint16_t i_sid
; /* 0 if raw mode */
103 typedef struct output_t
105 output_config_t config
;
109 packet_t
*p_packets
, *p_last_packet
;
111 mtime_t i_ref_timestamp
;
112 mtime_t i_ref_wallclock
;
116 mtime_t i_last_error
;
117 uint8_t *p_pat_section
;
118 uint8_t i_pat_version
, i_pat_cc
;
119 uint8_t *p_pmt_section
;
120 uint8_t i_pmt_version
, i_pmt_cc
;
121 uint8_t *p_nit_section
;
122 uint8_t i_nit_version
, i_nit_cc
;
123 uint8_t *p_sdt_section
;
124 uint8_t i_sdt_version
, i_sdt_cc
;
125 block_t
*p_eit_ts_buffer
;
126 uint8_t i_eit_ts_buffer_offset
, i_eit_cc
;
131 extern int i_verbose
;
132 extern output_t
**pp_outputs
;
133 extern int i_nb_outputs
;
134 extern output_t output_dup
;
135 extern char *psz_srv_socket
;
136 extern int i_adapter
;
138 extern int i_frequency
;
142 extern int i_rolloff
;
143 extern int i_voltage
;
145 extern int i_bandwidth
;
146 extern int i_inversion
;
147 extern char *psz_modulation
;
151 extern int i_transmission
;
152 extern int i_hierarchy
;
153 extern mtime_t i_frontend_timeout_duration
;
154 extern mtime_t i_quit_timeout
;
155 extern mtime_t i_quit_timeout_duration
;
156 extern int b_budget_mode
;
157 extern int b_select_pmts
;
158 extern int b_random_tsid
;
159 extern uint16_t i_network_id
;
160 extern uint8_t *p_network_name
;
161 extern size_t i_network_name_size
;
162 extern mtime_t i_wallclock
;
163 extern volatile int b_hup_received
;
164 extern int i_comm_fd
;
165 extern char *psz_udp_src
;
166 extern int i_asi_adapter
;
167 extern const char *psz_native_charset
;
168 extern const char *psz_dvb_charset
;
169 extern enum print_type_t i_print_type
;
171 extern void (*pf_Open
)( void );
172 extern block_t
* (*pf_Read
)( mtime_t i_poll_timeout
);
173 extern void (*pf_Reset
)( void );
174 extern int (*pf_SetFilter
)( uint16_t i_pid
);
175 extern void (*pf_UnsetFilter
)( int i_fd
, uint16_t i_pid
);
177 /*****************************************************************************
179 *****************************************************************************/
181 void config_Init( output_config_t
*p_config
);
182 void config_Free( output_config_t
*p_config
);
183 bool config_ParseHost( output_config_t
*p_config
, char *psz_string
);
185 /* Connect/Disconnect from syslogd */
186 void msg_Connect( const char *ident
);
187 void msg_Disconnect( void );
190 void msg_Info( void *_unused
, const char *psz_format
, ... );
191 void msg_Err( void *_unused
, const char *psz_format
, ... );
192 void msg_Warn( void *_unused
, const char *psz_format
, ... );
193 void msg_Dbg( void *_unused
, const char *psz_format
, ... );
194 void msg_Raw( void *_unused
, const char *psz_format
, ... );
197 mtime_t
mdate( void );
198 void msleep( mtime_t delay
);
199 void hexDump( uint8_t *p_data
, uint32_t i_len
);
200 struct addrinfo
*ParseNodeService( char *_psz_string
, char **ppsz_end
,
201 uint16_t i_default_port
);
203 void dvb_Open( void );
204 void dvb_Reset( void );
205 block_t
* dvb_Read( mtime_t i_poll_timeout
);
206 int dvb_SetFilter( uint16_t i_pid
);
207 void dvb_UnsetFilter( int i_fd
, uint16_t i_pid
);
208 uint8_t dvb_FrontendStatus( uint8_t *p_answer
, ssize_t
*pi_size
);
210 void udp_Open( void );
211 block_t
* udp_Read( mtime_t i_poll_timeout
);
212 void udp_Reset( void );
213 int udp_SetFilter( uint16_t i_pid
);
214 void udp_UnsetFilter( int i_fd
, uint16_t i_pid
);
216 void asi_Open( void );
217 block_t
* asi_Read( mtime_t i_poll_timeout
);
218 void asi_Reset( void );
219 int asi_SetFilter( uint16_t i_pid
);
220 void asi_UnsetFilter( int i_fd
, uint16_t i_pid
);
222 void demux_Open( void );
223 void demux_Run( block_t
*p_ts
);
224 void demux_Change( output_t
*p_output
, const output_config_t
*p_config
);
225 void demux_ResendCAPMTs( void );
226 bool demux_PIDIsSelected( uint16_t i_pid
);
227 char *demux_Iconv(void *_unused
, const char *psz_encoding
,
228 char *p_string
, size_t i_length
);
231 output_t
*output_Create( const output_config_t
*p_config
);
232 int output_Init( output_t
*p_output
, const output_config_t
*p_config
);
233 void output_Close( output_t
*p_output
);
234 void output_Put( output_t
*p_output
, block_t
*p_block
);
235 mtime_t
output_Send( void );
236 output_t
*output_Find( const output_config_t
*p_config
);
237 void output_Change( output_t
*p_output
, const output_config_t
*p_config
);
239 void comm_Open( void );
240 void comm_Read( void );
242 /*****************************************************************************
244 *****************************************************************************/
245 static inline block_t
*block_New( void )
247 block_t
*p_block
= malloc(sizeof(block_t
));
248 p_block
->p_next
= NULL
;
249 p_block
->i_refcount
= 1;
253 /*****************************************************************************
255 *****************************************************************************/
256 static inline void block_Delete( block_t
*p_block
)
261 /*****************************************************************************
263 *****************************************************************************/
264 static inline void block_DeleteChain( block_t
*p_block
)
266 while ( p_block
!= NULL
)
268 block_t
*p_next
= p_block
->p_next
;