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
169 /*******************************************************************************
170 * program_descriptor_t
171 *******************************************************************************
172 * Describes a program and list associated elementary streams. It is build by
173 * the PSI decoder upon the informations carried in program map sections
174 *******************************************************************************/
177 /* Program characteristics */
178 u16 i_number; /* program number */
179 u8 i_version; /* version number */
180 boolean_t b_is_ok; /* Is the description up to date ?*/
181 u16 i_pcr_pid; /* PCR ES */
184 es_descriptor_t ** ap_es; /* array of pointers to ES */
186 #ifdef DVB_EXTENSIONS
187 /* Service Descriptor (program name) */
192 /* ?? target background grid descriptor ? */
193 /* ?? video window descriptor ? */
194 /* ?? ISO 639 language descriptor ? */
202 /*******************************************************************************
204 *******************************************************************************
205 * Contains informations used to synchronise the decoder with the server
206 *******************************************************************************/
208 typedef struct pcr_descriptor_struct
210 vlc_mutex_t lock; /* pcr modification lock */
213 mtime_t delta_decode;
214 /* represents decoder_time - pcr_time in usecondes */
218 /* counter used to compute dynamic average values */
222 count_t c_average_jitter;
223 mtime_t max_jitter; /* the evalueted maximum jitter */
224 mtime_t average_jitter; /* the evalueted average jitter */
225 count_t c_pcr; /* the number of PCR which have been decoded */
229 /*******************************************************************************
230 * stream_descriptor_t
231 *******************************************************************************
232 * Describes a transport stream and list its associated programs. Build upon
233 * the informations carried in program association sections
234 *******************************************************************************/
237 u16 i_stream_id; /* stream id */
239 /* Program Association Table status */
240 u8 i_PAT_version; /* version number */
241 boolean_t b_is_PAT_complete; /* Is the PAT complete ?*/
242 u8 i_known_PAT_sections; /* Number of section we received so far */
243 byte_t a_known_PAT_sections[32]; /* Already received sections */
245 /* Program Map Table status */
246 boolean_t b_is_PMT_complete; /* Is the PMT complete ?*/
247 u8 i_known_PMT_sections; /* Number of section we received so far */
248 byte_t a_known_PMT_sections[32]; /* Already received sections */
250 /* Service Description Table status */
251 u8 i_SDT_version; /* version number */
252 boolean_t b_is_SDT_complete; /* Is the SDT complete ?*/
253 u8 i_known_SDT_sections; /* Number of section we received so far */
254 byte_t a_known_SDT_sections[32]; /* Already received sections */
256 /* Programs description */
257 int i_pgrm_number; /* Number of program number we have */
258 pgrm_descriptor_t ** ap_programs; /* Array of pointers to pgrm */
264 } stream_descriptor_t;
266 /*******************************************************************************
268 *******************************************************************************/
271 vlc_mutex_t lock; /* netlist modification lock */
272 struct iovec p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
273 /* FIFO or LIFO of free TS packets */
274 ts_packet_t * p_ts_packets;
275 /* pointer to the first TS packet we allocated */
277 pes_packet_t * p_pes_free[INPUT_MAX_PES + 1];
278 /* FIFO or LIFO of free PES packets */
279 pes_packet_t * p_pes_packets;
280 /* pointer to the first PES packet we allocated */
282 /* To use the efficiency of the scatter/gather IO operations. We implemented it
283 * in 2 ways, as we don't know yet which one is better : as a FIFO (code
284 * simplier) or as a LIFO stack (when we doesn't care of the ordering, this
285 * allow to drastically improve the cache performance) */
286 #ifdef INPUT_LIFO_TS_NETLIST
289 int i_ts_start, i_ts_end;
291 #ifdef INPUT_LIFO_PES_NETLIST
294 int i_pes_start, i_pes_end;
298 /*******************************************************************************
300 *******************************************************************************
301 * This structure includes all the local static variables of an input thread,
302 * including the netlist and the ES descriptors
303 * Note that p_es must be defined as a static table, otherwise we would have to
304 * update all reference to it each time the table would be reallocated
305 *******************************************************************************/
307 /* function pointers */
308 struct input_thread_struct;
309 struct input_cfg_struct;
310 typedef int (*f_open_t)( struct input_thread_struct *, struct input_cfg_struct *);
311 typedef int (*f_read_t)( struct input_thread_struct *, const struct iovec *,
313 typedef void (*f_clean_t)( struct input_thread_struct * );
315 typedef struct input_thread_struct
317 /* Thread properties and locks */
318 boolean_t b_die; /* 'die' flag */
319 boolean_t b_error; /* deadlock */
320 vlc_thread_t thread_id; /* id for thread functions */
321 vlc_mutex_t programs_lock; /* programs modification lock */
322 vlc_mutex_t es_lock; /* es modification lock */
324 /* Input method description */
325 int i_method; /* input method */
326 int i_handle; /* file/socket descriptor */
327 int i_vlan_id; /* id for vlan method */
328 f_open_t p_open; /* pointer to the opener of the method */
329 f_read_t p_read; /* pointer to the reading function */
330 f_clean_t p_clean; /* pointer to the destroying function */
332 /* General stream description */
333 stream_descriptor_t * p_stream; /* PAT tables */
334 es_descriptor_t p_es[INPUT_MAX_ES]; /* carried elementary streams */
335 pcr_descriptor_t * p_pcr; /* PCR struct used for synchronisation */
337 /* List of streams to demux */
338 es_descriptor_t * pp_selected_es[INPUT_MAX_SELECTED_ES];
341 input_netlist_t netlist; /* see above */
343 /* ?? default settings for new decoders */
344 struct aout_thread_s * p_aout; /* audio output thread structure */
348 count_t c_loops; /* number of loops */
349 count_t c_bytes; /* total of bytes read */
350 count_t c_payload_bytes; /* total of payload useful bytes */
351 count_t c_ts_packets_read; /* total of packets read */
352 count_t c_ts_packets_trashed; /* total of trashed packets */
353 /* ?? ... other stats */
358 #define INPUT_METHOD_NONE 0 /* input thread is inactive */
359 #define INPUT_METHOD_TS_FILE 10 /* TS stream is read from a file */
360 #define INPUT_METHOD_TS_UCAST 20 /* TS UDP unicast */
361 #define INPUT_METHOD_TS_MCAST 21 /* TS UDP multicast */
362 #define INPUT_METHOD_TS_BCAST 22 /* TS UDP broadcast */
363 #define INPUT_METHOD_TS_VLAN_BCAST 32 /* TS UDP broadcast with VLANs */
365 /*******************************************************************************
366 * input_cfg_t: input thread configuration structure
367 *******************************************************************************
368 * This structure is passed as a parameter to input_CreateTtread(). It includes
369 * several fields describing potential properties of a new object.
370 * The 'i_properties' field allow to set only a subset of the required
371 * properties, asking the called function to use default settings for
373 *******************************************************************************/
374 typedef struct input_cfg_struct
378 /* Input method properties */
379 int i_method; /* input method */
380 char * psz_filename; /* filename */
381 char * psz_hostname; /* server hostname */
382 char * psz_ip; /* server IP */
383 int i_port; /* port */
384 int i_vlan; /* vlan number */
386 /* ??... default settings for new decoders */
387 struct aout_thread_s * p_aout; /* audio output thread structure */
391 /* Properties flags */
392 #define INPUT_CFG_METHOD (1 << 0)
393 #define INPUT_CFG_FILENAME (1 << 4)
394 #define INPUT_CFG_HOSTNAME (1 << 8)
395 #define INPUT_CFG_IP (1 << 9)
396 #define INPUT_CFG_PORT (1 << 10)
397 #define INPUT_CFG_VLAN (1 << 11)
399 /******************************************************************************
401 ******************************************************************************/
402 input_thread_t *input_CreateThread ( input_cfg_t *p_cfg );
403 void input_DestroyThread ( input_thread_t *p_input );
405 int input_OpenAudioStream ( input_thread_t *p_input, int i_pid
406 /* ?? , struct audio_cfg_s * p_cfg */ );
407 void input_CloseAudioStream ( input_thread_t *p_input, int i_pid );
408 int input_OpenVideoStream ( input_thread_t *p_input,
409 struct vout_thread_s *p_vout, struct video_cfg_s * p_cfg );
410 void input_CloseVideoStream ( input_thread_t *p_input, int i_pid );
412 /* ?? settings functions */
413 /* ?? info functions */