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;
243 /* Number of section we received so far */
244 byte_t a_known_PAT_sections[32];
245 /* Already received sections */
247 /* Program Map Table status */
248 boolean_t b_is_PMT_complete; /* Is the PMT complete ?*/
249 u8 i_known_PMT_sections;
250 /* Number of section we received so far */
251 byte_t a_known_PMT_sections[32];
252 /* Already received sections */
254 /* Service Description Table status */
255 u8 i_SDT_version; /* version number */
256 boolean_t b_is_SDT_complete; /* Is the SDT complete ?*/
257 u8 i_known_SDT_sections;
258 /* Number of section we received so far */
259 byte_t a_known_SDT_sections[32];
260 /* Already received sections */
262 /* Programs description */
263 int i_pgrm_number; /* Number of program number we have */
264 pgrm_descriptor_t ** ap_programs; /* Array of pointers to pgrm */
270 } stream_descriptor_t;
272 /******************************************************************************
274 ******************************************************************************/
277 vlc_mutex_t lock; /* netlist modification lock */
278 struct iovec p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
279 /* FIFO or LIFO of free TS packets */
280 ts_packet_t * p_ts_packets;
281 /* pointer to the first TS packet we allocated */
283 pes_packet_t * p_pes_free[INPUT_MAX_PES + 1];
284 /* FIFO or LIFO of free PES packets */
285 pes_packet_t * p_pes_packets;
286 /* pointer to the first PES packet we allocated */
288 /* To use the efficiency of the scatter/gather IO operations. We implemented
289 * it in 2 ways, as we don't know yet which one is better : as a FIFO (code
290 * simplier) or as a LIFO stack (when we doesn't care of the ordering, this
291 * allow to drastically improve the cache performance) */
292 #ifdef INPUT_LIFO_TS_NETLIST
295 int i_ts_start, i_ts_end;
297 #ifdef INPUT_LIFO_PES_NETLIST
300 int i_pes_start, i_pes_end;
304 /******************************************************************************
306 ******************************************************************************
307 * This structure includes all the local static variables of an input thread,
308 * including the netlist and the ES descriptors
309 * Note that p_es must be defined as a static table, otherwise we would have to
310 * update all reference to it each time the table would be reallocated
311 ******************************************************************************/
313 /* function pointers */
314 struct input_thread_struct;
315 struct input_cfg_struct;
316 typedef int (*f_open_t)( struct input_thread_struct *, struct input_cfg_struct *);
317 typedef int (*f_read_t)( struct input_thread_struct *, const struct iovec *,
319 typedef void (*f_clean_t)( struct input_thread_struct * );
321 typedef struct input_thread_struct
323 /* Thread properties and locks */
324 boolean_t b_die; /* 'die' flag */
325 boolean_t b_error; /* deadlock */
326 vlc_thread_t thread_id; /* id for thread functions */
327 vlc_mutex_t programs_lock; /* programs modification lock */
328 vlc_mutex_t es_lock; /* es modification lock */
330 /* Input method description */
331 int i_method; /* input method */
332 int i_handle; /* file/socket descriptor */
333 int i_vlan_id; /* id for vlan method */
334 f_open_t p_open; /* pointer to the opener of the method */
335 f_read_t p_read; /* pointer to the reading function */
336 f_clean_t p_clean; /* pointer to the destroying function */
338 /* General stream description */
339 stream_descriptor_t * p_stream; /* PAT tables */
340 es_descriptor_t p_es[INPUT_MAX_ES]; /* carried elementary streams */
341 pcr_descriptor_t * p_pcr; /* PCR struct used for synchronisation */
343 /* List of streams to demux */
344 es_descriptor_t * pp_selected_es[INPUT_MAX_SELECTED_ES];
347 input_netlist_t netlist; /* see above */
349 /* ?? default settings for new decoders */
350 struct aout_thread_s * p_aout; /* audio output thread structure */
354 count_t c_loops; /* number of loops */
355 count_t c_bytes; /* total of bytes read */
356 count_t c_payload_bytes; /* total of payload useful bytes */
357 count_t c_ts_packets_read; /* total of packets read */
358 count_t c_ts_packets_trashed; /* total of trashed packets */
359 /* ?? ... other stats */
364 #define INPUT_METHOD_NONE 0 /* input thread is inactive */
365 #define INPUT_METHOD_TS_FILE 10 /* TS stream is read from a file */
366 #define INPUT_METHOD_TS_UCAST 20 /* TS UDP unicast */
367 #define INPUT_METHOD_TS_MCAST 21 /* TS UDP multicast */
368 #define INPUT_METHOD_TS_BCAST 22 /* TS UDP broadcast */
369 #define INPUT_METHOD_TS_VLAN_BCAST 32 /* TS UDP broadcast with VLANs */
371 /******************************************************************************
372 * input_cfg_t: input thread configuration structure
373 ******************************************************************************
374 * This structure is passed as a parameter to input_CreateTtread(). It includes
375 * several fields describing potential properties of a new object.
376 * The 'i_properties' field allow to set only a subset of the required
377 * properties, asking the called function to use default settings for
379 ******************************************************************************/
380 typedef struct input_cfg_struct
384 /* Input method properties */
385 int i_method; /* input method */
386 char * psz_filename; /* filename */
387 char * psz_hostname; /* server hostname */
388 char * psz_ip; /* server IP */
389 int i_port; /* port */
390 int i_vlan; /* vlan number */
392 /* ??... default settings for new decoders */
393 struct aout_thread_s * p_aout; /* audio output thread structure */
397 /* Properties flags */
398 #define INPUT_CFG_METHOD (1 << 0)
399 #define INPUT_CFG_FILENAME (1 << 4)
400 #define INPUT_CFG_HOSTNAME (1 << 8)
401 #define INPUT_CFG_IP (1 << 9)
402 #define INPUT_CFG_PORT (1 << 10)
403 #define INPUT_CFG_VLAN (1 << 11)
405 /*****************************************************************************
407 *****************************************************************************/
408 input_thread_t *input_CreateThread ( input_cfg_t *p_cfg );
409 void input_DestroyThread ( input_thread_t *p_input );
411 int input_OpenAudioStream ( input_thread_t *p_input, int i_pid
412 /* ?? , struct audio_cfg_s * p_cfg */ );
413 void input_CloseAudioStream ( input_thread_t *p_input, int i_pid );
414 int input_OpenVideoStream ( input_thread_t *p_input,
415 struct vout_thread_s *p_vout, struct video_cfg_s * p_cfg );
416 void input_CloseVideoStream ( input_thread_t *p_input, int i_pid );
418 /* ?? settings functions */
419 /* ?? info functions */