1 /*******************************************************************************
2 * input.h: input thread interface
4 *******************************************************************************/
6 /* needs : "netlist.h", "config.h", "mtime.h" */
9 * tables version control */
11 /*******************************************************************************
13 *******************************************************************************
14 * These structures, required here only as pointers destinations, are declared
16 *******************************************************************************/
17 struct video_cfg_s; /* video configuration descriptor */
18 struct vout_thread_s; /* video output thread */
19 struct stream_descriptor_s; /* PSI tables */
21 /*******************************************************************************
22 * Constants related to input
23 *******************************************************************************/
24 #define TS_PACKET_SIZE 188 /* size of a TS packet */
25 #define PES_HEADER_SIZE 14 /* size of the first part of a PES header */
26 #define PSI_SECTION_SIZE 4096 /* Maximum size of a PSI section */
28 /*******************************************************************************
30 *******************************************************************************
31 * Describe a TS packet.
32 *******************************************************************************/
33 typedef struct ts_packet_struct
35 /* Nothing before this line, the code relies on that */
36 byte_t buffer[TS_PACKET_SIZE]; /* raw TS data packet */
38 /* Decoders information */
39 unsigned int i_payload_start;
40 /* start of the PES payload in this packet */
41 unsigned int i_payload_end; /* guess ? :-) */
43 /* Used to chain the TS packets that carry data for a same PES or PSI */
44 struct ts_packet_struct * p_prev_ts;
45 struct ts_packet_struct * p_next_ts;
49 /*******************************************************************************
51 *******************************************************************************
52 * Describes an PES packet, with its properties, and pointers to the TS packets
54 *******************************************************************************/
58 boolean_t b_data_loss; /* The previous (at least) PES packet
59 * has been lost. The decoders will have to find a way to recover. */
60 boolean_t b_data_alignment; /* used to find the beginning of a
61 * video or audio unit */
62 boolean_t b_has_pts; /* is the following field set ? */
63 mtime_t i_pts; /* the PTS for this packet (if set above) */
64 boolean_t b_random_access;
65 /* if TRUE, in the payload of this packet, there is the first byte
66 * of a video sequence header, or the first byte of an audio frame.
68 u8 i_stream_id; /* payload type and id */
69 int i_pes_size; /* size of the current PES packet */
70 int i_ts_packets; /* number of TS packets in this PES */
72 /* Demultiplexer environment */
73 boolean_t b_discard_payload; /* is the packet messed up ? */
74 byte_t * p_pes_header; /* pointer to the PES header */
75 byte_t * p_pes_header_save; /* temporary buffer */
77 /* Pointers to TS packets (TS packets are then linked by the p_prev_ts and
78 p_next_ts fields of the ts_packet_t struct) */
79 ts_packet_t * p_first_ts; /* The first TS packet containing this
80 * PES (used by decoders). */
81 ts_packet_t * p_last_ts; /* The last TS packet gathered at present
82 * (used by the demultiplexer). */
86 /*******************************************************************************
88 *******************************************************************************
89 * Describes a PSI section. Beware, it doesn't contain pointers to the TS
90 * packets that contain it as for a PES, but the data themselves
91 *******************************************************************************/
94 byte_t buffer[PSI_SECTION_SIZE];
96 boolean_t b_running_section; /* Is there a section being decoded ? */
99 u16 i_current_position;
103 /*******************************************************************************
104 * es_descriptor_t: elementary stream descriptor
105 *******************************************************************************
106 * Describes an elementary stream, and includes fields required to handle and
107 * demultiplex this elementary stream.
108 *******************************************************************************/
111 u16 i_id; /* stream ID, PID for TS streams */
112 u8 i_type; /* stream type */
114 boolean_t b_pcr; /* does the stream include a PCR ? */
115 /* ?? b_pcr will be replaced by something else: since a PCR can't be shared
116 * between several ES, we will probably store the PCR fields directly here,
117 * and one of those fields will probably (again) be used as a test of the
119 boolean_t b_psi; /* does the stream have to be handled by the
122 int i_continuity_counter;
123 boolean_t b_discontinuity;
127 pes_packet_t * p_pes_packet;
128 /* current PES packet we are gathering */
131 psi_section_t * p_psi_section; /* idem for a PSI stream */
133 /* Decoder informations */
134 void * p_dec; /* p_dec is void *, since we don't know a
135 * priori whether it is adec_thread_t or
136 * vdec_thread_t. We will use explicit
139 /* ?? video stream descriptor ? */
140 /* ?? audio stream descriptor ? */
141 /* ?? hierarchy descriptor ? */
142 /* ?? target background grid descriptor ? */
143 /* ?? video window descriptor ? */
144 /* ?? ISO 639 language descriptor ? */
148 count_t c_bytes; /* total bytes read */
149 count_t c_payload_bytes; /* total of payload usefull bytes */
150 count_t c_packets; /* total packets read */
151 count_t c_invalid_packets; /* invalid packets read */
152 /* ?? ... other stats */
156 /* Special PID values - note that the PID is only on 13 bits, and that values
157 * greater than 0x1fff have no meaning in a stream */
158 #define PROGRAM_ASSOCIATION_TABLE_PID 0x0000
159 #define CONDITIONNAL_ACCESS_TABLE_PID 0x0001 /* not used */
160 #define EMPTY_PID 0xffff /* empty record in a table */
162 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
163 #define MPEG1_VIDEO_ES 0x01
164 #define MPEG2_VIDEO_ES 0x02
165 #define MPEG1_AUDIO_ES 0x03
166 #define MPEG2_AUDIO_ES 0x04
167 #define AC3_AUDIO_ES 0x05
170 /*******************************************************************************
171 * program_descriptor_t
172 *******************************************************************************
173 * Describes a program and list associated elementary streams. It is build by
174 * the PSI decoder upon the informations carried in program map sections
175 *******************************************************************************/
178 /* Program characteristics */
179 u16 i_number; /* program number */
180 u8 i_version; /* version number */
181 boolean_t b_is_ok; /* Is the description up to date ?*/
182 u16 i_pcr_pid; /* PCR ES */
185 es_descriptor_t ** ap_es; /* array of pointers to ES */
187 #ifdef DVB_EXTENSIONS
188 /* Service Descriptor (program name) */
193 /* ?? target background grid descriptor ? */
194 /* ?? video window descriptor ? */
195 /* ?? ISO 639 language descriptor ? */
203 /*******************************************************************************
205 *******************************************************************************
206 * Contains informations used to synchronise the decoder with the server
207 *******************************************************************************/
209 typedef struct pcr_descriptor_struct
211 vlc_mutex_t lock; /* pcr modification lock */
214 mtime_t delta_decode;
215 /* represents decoder_time - pcr_time in usecondes */
219 /* counter used to compute dynamic average values */
223 count_t c_average_jitter;
224 mtime_t max_jitter; /* the evalueted maximum jitter */
225 mtime_t average_jitter; /* the evalueted average jitter */
226 count_t c_pcr; /* the number of PCR which have been decoded */
230 /*******************************************************************************
231 * stream_descriptor_t
232 *******************************************************************************
233 * Describes a transport stream and list its associated programs. Build upon
234 * the informations carried in program association sections
235 *******************************************************************************/
238 u16 i_stream_id; /* stream id */
240 /* Program Association Table status */
241 u8 i_PAT_version; /* version number */
242 boolean_t b_is_PAT_complete; /* Is the PAT complete ?*/
243 u8 i_known_PAT_sections; /* Number of section we received so far */
244 byte_t a_known_PAT_sections[32]; /* Already received sections */
246 /* Program Map Table status */
247 boolean_t b_is_PMT_complete; /* Is the PMT complete ?*/
248 u8 i_known_PMT_sections; /* Number of section we received so far */
249 byte_t a_known_PMT_sections[32]; /* Already received sections */
251 /* Service Description Table status */
252 u8 i_SDT_version; /* version number */
253 boolean_t b_is_SDT_complete; /* Is the SDT complete ?*/
254 u8 i_known_SDT_sections; /* Number of section we received so far */
255 byte_t a_known_SDT_sections[32]; /* Already received sections */
257 /* Programs description */
258 int i_pgrm_number; /* Number of program number we have */
259 pgrm_descriptor_t ** ap_programs; /* Array of pointers to pgrm */
265 } stream_descriptor_t;
267 /*******************************************************************************
269 *******************************************************************************/
272 vlc_mutex_t lock; /* netlist modification lock */
273 struct iovec p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
274 /* FIFO or LIFO of free TS packets */
275 ts_packet_t * p_ts_packets;
276 /* pointer to the first TS packet we allocated */
278 pes_packet_t * p_pes_free[INPUT_MAX_PES + 1];
279 /* FIFO or LIFO of free PES packets */
280 pes_packet_t * p_pes_packets;
281 /* pointer to the first PES packet we allocated */
283 /* To use the efficiency of the scatter/gather IO operations. We implemented it
284 * in 2 ways, as we don't know yet which one is better : as a FIFO (code
285 * simplier) or as a LIFO stack (when we doesn't care of the ordering, this
286 * allow to drastically improve the cache performance) */
287 #ifdef INPUT_LIFO_TS_NETLIST
290 int i_ts_start, i_ts_end;
292 #ifdef INPUT_LIFO_PES_NETLIST
295 int i_pes_start, i_pes_end;
299 /*******************************************************************************
301 *******************************************************************************
302 * This structure includes all the local static variables of an input thread,
303 * including the netlist and the ES descriptors
304 * Note that p_es must be defined as a static table, otherwise we would have to
305 * update all reference to it each time the table would be reallocated
306 *******************************************************************************/
308 /* function pointers */
309 struct input_thread_struct;
310 struct input_cfg_struct;
311 typedef int (*f_open_t)( struct input_thread_struct *, struct input_cfg_struct *);
312 typedef int (*f_read_t)( struct input_thread_struct *, const struct iovec *,
314 typedef void (*f_clean_t)( struct input_thread_struct * );
316 typedef struct input_thread_struct
318 /* Thread properties and locks */
319 boolean_t b_die; /* 'die' flag */
320 boolean_t b_error; /* deadlock */
321 vlc_thread_t thread_id; /* id for thread functions */
322 vlc_mutex_t programs_lock; /* programs modification lock */
323 vlc_mutex_t es_lock; /* es modification lock */
325 /* Input method description */
326 int i_method; /* input method */
327 int i_handle; /* file/socket descriptor */
328 int i_vlan_id; /* id for vlan method */
329 f_open_t p_open; /* pointer to the opener of the method */
330 f_read_t p_read; /* pointer to the reading function */
331 f_clean_t p_clean; /* pointer to the destroying function */
333 /* General stream description */
334 stream_descriptor_t * p_stream; /* PAT tables */
335 es_descriptor_t p_es[INPUT_MAX_ES]; /* carried elementary streams */
336 pcr_descriptor_t * p_pcr; /* PCR struct used for synchronisation */
338 /* List of streams to demux */
339 es_descriptor_t * pp_selected_es[INPUT_MAX_SELECTED_ES];
342 input_netlist_t netlist; /* see above */
344 /* ?? default settings for new decoders */
345 struct aout_thread_s * p_aout; /* audio output thread structure */
349 count_t c_loops; /* number of loops */
350 count_t c_bytes; /* total of bytes read */
351 count_t c_payload_bytes; /* total of payload useful bytes */
352 count_t c_ts_packets_read; /* total of packets read */
353 count_t c_ts_packets_trashed; /* total of trashed packets */
354 /* ?? ... other stats */
359 #define INPUT_METHOD_NONE 0 /* input thread is inactive */
360 #define INPUT_METHOD_TS_FILE 10 /* TS stream is read from a file */
361 #define INPUT_METHOD_TS_UCAST 20 /* TS UDP unicast */
362 #define INPUT_METHOD_TS_MCAST 21 /* TS UDP multicast */
363 #define INPUT_METHOD_TS_BCAST 22 /* TS UDP broadcast */
364 #define INPUT_METHOD_TS_VLAN_BCAST 32 /* TS UDP broadcast with VLANs */
366 /*******************************************************************************
367 * input_cfg_t: input thread configuration structure
368 *******************************************************************************
369 * This structure is passed as a parameter to input_CreateTtread(). It includes
370 * several fields describing potential properties of a new object.
371 * The 'i_properties' field allow to set only a subset of the required
372 * properties, asking the called function to use default settings for
374 *******************************************************************************/
375 typedef struct input_cfg_struct
379 /* Input method properties */
380 int i_method; /* input method */
381 char * psz_filename; /* filename */
382 char * psz_hostname; /* server hostname */
383 char * psz_ip; /* server IP */
384 int i_port; /* port */
385 int i_vlan; /* vlan number */
387 /* ??... default settings for new decoders */
388 struct aout_thread_s * p_aout; /* audio output thread structure */
392 /* Properties flags */
393 #define INPUT_CFG_METHOD (1 << 0)
394 #define INPUT_CFG_FILENAME (1 << 4)
395 #define INPUT_CFG_HOSTNAME (1 << 8)
396 #define INPUT_CFG_IP (1 << 9)
397 #define INPUT_CFG_PORT (1 << 10)
398 #define INPUT_CFG_VLAN (1 << 11)
400 /******************************************************************************
402 ******************************************************************************/
403 input_thread_t *input_CreateThread ( input_cfg_t *p_cfg );
404 void input_DestroyThread ( input_thread_t *p_input );
406 int input_OpenAudioStream ( input_thread_t *p_input, int i_pid
407 /* ?? , struct audio_cfg_s * p_cfg */ );
408 void input_CloseAudioStream ( input_thread_t *p_input, int i_pid );
409 int input_OpenVideoStream ( input_thread_t *p_input,
410 struct vout_thread_s *p_vout, struct video_cfg_s * p_cfg );
411 void input_CloseVideoStream ( input_thread_t *p_input, int i_pid );
413 /* ?? settings functions */
414 /* ?? info functions */