1 /******************************************************************************
2 * input.h: input thread interface
4 ******************************************************************************/
6 /******************************************************************************
7 * Constants related to input
8 ******************************************************************************/
9 #define TS_PACKET_SIZE 188 /* size of a TS packet */
10 #define PES_HEADER_SIZE 14 /* size of the first part of a PES header */
11 #define PSI_SECTION_SIZE 4096 /* Maximum size of a PSI section */
13 /******************************************************************************
15 ******************************************************************************
16 * Describe a TS packet.
17 ******************************************************************************/
18 typedef struct ts_packet_s
20 /* Nothing before this line, the code relies on that */
21 byte_t buffer[TS_PACKET_SIZE]; /* raw TS data packet */
23 /* Decoders information */
24 unsigned int i_payload_start;
25 /* start of the PES payload in this packet */
26 unsigned int i_payload_end; /* guess ? :-) */
28 /* Used to chain the TS packets that carry data for a same PES or PSI */
29 struct ts_packet_s * p_prev_ts;
30 struct ts_packet_s * p_next_ts;
33 /******************************************************************************
35 ******************************************************************************
36 * Describes an PES packet, with its properties, and pointers to the TS packets
38 ******************************************************************************/
39 typedef struct pes_packet_s
42 boolean_t b_data_loss; /* The previous (at least) PES packet
43 * has been lost. The decoders will have to find a way to recover. */
44 boolean_t b_data_alignment; /* used to find the beginning of a
45 * video or audio unit */
46 boolean_t b_has_pts; /* is the following field set ? */
47 mtime_t i_pts; /* the PTS for this packet (if set above) */
48 boolean_t b_random_access;
49 /* if TRUE, in the payload of this packet, there is the first byte
50 * of a video sequence header, or the first byte of an audio frame.
52 u8 i_stream_id; /* payload type and id */
53 int i_pes_size; /* size of the current PES packet */
54 int i_ts_packets; /* number of TS packets in this PES */
56 /* Demultiplexer environment */
57 boolean_t b_discard_payload; /* is the packet messed up ? */
58 byte_t * p_pes_header; /* pointer to the PES header */
59 byte_t * p_pes_header_save; /* temporary buffer */
61 /* Pointers to TS packets (TS packets are then linked by the p_prev_ts and
62 p_next_ts fields of the ts_packet_t struct) */
63 ts_packet_t * p_first_ts; /* The first TS packet containing this
64 * PES (used by decoders). */
65 ts_packet_t * p_last_ts; /* The last TS packet gathered at present
66 * (used by the demultiplexer). */
69 /******************************************************************************
71 ******************************************************************************
72 * Describes a PSI section. Beware, it doesn't contain pointers to the TS
73 * packets that contain it as for a PES, but the data themselves
74 ******************************************************************************/
75 typedef struct psi_section_s
77 byte_t buffer[PSI_SECTION_SIZE];
79 boolean_t b_running_section; /* Is there a section being decoded ? */
82 u16 i_current_position;
86 /******************************************************************************
87 * es_descriptor_t: elementary stream descriptor
88 ******************************************************************************
89 * Describes an elementary stream, and includes fields required to handle and
90 * demultiplex this elementary stream.
91 ******************************************************************************/
92 typedef struct es_descriptor_t
94 u16 i_id; /* stream ID, PID for TS streams */
95 u8 i_type; /* stream type */
97 boolean_t b_pcr; /* does the stream include a PCR ? */
98 /* ?? b_pcr will be replaced by something else: since a PCR can't be shared
99 * between several ES, we will probably store the PCR fields directly here,
100 * and one of those fields will probably (again) be used as a test of the
102 boolean_t b_psi; /* does the stream have to be handled by the
105 int i_continuity_counter;
106 boolean_t b_discontinuity;
110 pes_packet_t * p_pes_packet;
111 /* current PES packet we are gathering */
114 psi_section_t * p_psi_section; /* idem for a PSI stream */
116 /* Decoder informations */
117 void * p_dec; /* p_dec is void *, since we don't know a
118 * priori whether it is adec_thread_t or
119 * vdec_thread_t. We will use explicit
122 /* ?? video stream descriptor ? */
123 /* ?? audio stream descriptor ? */
124 /* ?? hierarchy descriptor ? */
125 /* ?? target background grid descriptor ? */
126 /* ?? video window descriptor ? */
127 /* ?? ISO 639 language descriptor ? */
131 count_t c_bytes; /* total bytes read */
132 count_t c_payload_bytes;/* total of payload usefull bytes */
133 count_t c_packets; /* total packets read */
134 count_t c_invalid_packets; /* invalid packets read */
135 /* ?? ... other stats */
139 /* Special PID values - note that the PID is only on 13 bits, and that values
140 * greater than 0x1fff have no meaning in a stream */
141 #define PROGRAM_ASSOCIATION_TABLE_PID 0x0000
142 #define CONDITIONNAL_ACCESS_TABLE_PID 0x0001 /* not used */
143 #define EMPTY_PID 0xffff /* empty record in a table */
145 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
146 #define MPEG1_VIDEO_ES 0x01
147 #define MPEG2_VIDEO_ES 0x02
148 #define MPEG1_AUDIO_ES 0x03
149 #define MPEG2_AUDIO_ES 0x04
150 #define AC3_AUDIO_ES 0x81
152 /******************************************************************************
153 * program_descriptor_t
154 ******************************************************************************
155 * Describes a program and list associated elementary streams. It is build by
156 * the PSI decoder upon the informations carried in program map sections
157 ******************************************************************************/
160 /* Program characteristics */
161 u16 i_number; /* program number */
162 u8 i_version; /* version number */
163 boolean_t b_is_ok; /* Is the description up to date ?*/
164 u16 i_pcr_pid; /* PCR ES */
167 es_descriptor_t ** ap_es; /* array of pointers to ES */
169 #ifdef DVB_EXTENSIONS
170 /* Service Descriptor (program name) */
175 /* ?? target background grid descriptor ? */
176 /* ?? video window descriptor ? */
177 /* ?? ISO 639 language descriptor ? */
185 /******************************************************************************
187 ******************************************************************************
188 * Contains informations used to synchronise the decoder with the server
189 ******************************************************************************/
191 typedef struct pcr_descriptor_struct
193 /* system_date = PTS_date + delta_pcr + delta_absolute */
195 mtime_t delta_absolute;
200 count_t c_average_count;
201 /* counter used to compute dynamic average values */
204 /******************************************************************************
205 * stream_descriptor_t
206 ******************************************************************************
207 * Describes a transport stream and list its associated programs. Build upon
208 * the informations carried in program association sections
209 ******************************************************************************/
212 u16 i_stream_id; /* stream id */
214 /* Program Association Table status */
215 u8 i_PAT_version; /* version number */
216 boolean_t b_is_PAT_complete; /* Is the PAT complete ?*/
217 u8 i_known_PAT_sections;
218 /* Number of section we received so far */
219 byte_t a_known_PAT_sections[32];
220 /* Already received sections */
222 /* Program Map Table status */
223 boolean_t b_is_PMT_complete; /* Is the PMT complete ?*/
224 u8 i_known_PMT_sections;
225 /* Number of section we received so far */
226 byte_t a_known_PMT_sections[32];
227 /* Already received sections */
229 /* Service Description Table status */
230 u8 i_SDT_version; /* version number */
231 boolean_t b_is_SDT_complete; /* Is the SDT complete ?*/
232 u8 i_known_SDT_sections;
233 /* Number of section we received so far */
234 byte_t a_known_SDT_sections[32];
235 /* Already received sections */
237 /* Programs description */
238 int i_pgrm_number; /* Number of program number we have */
239 pgrm_descriptor_t ** ap_programs; /* Array of pointers to pgrm */
245 } stream_descriptor_t;
247 /******************************************************************************
249 ******************************************************************************/
252 vlc_mutex_t lock; /* netlist modification lock */
253 struct iovec p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
254 /* FIFO or LIFO of free TS packets */
255 ts_packet_t * p_ts_packets;
256 /* pointer to the first TS packet we allocated */
258 pes_packet_t * p_pes_free[INPUT_MAX_PES + 1];
259 /* FIFO or LIFO of free PES packets */
260 pes_packet_t * p_pes_packets;
261 /* pointer to the first PES packet we allocated */
263 /* To use the efficiency of the scatter/gather IO operations. We implemented
264 * it in 2 ways, as we don't know yet which one is better : as a FIFO (code
265 * simplier) or as a LIFO stack (when we doesn't care of the ordering, this
266 * allow to drastically improve the cache performance) */
267 #ifdef INPUT_LIFO_TS_NETLIST
270 int i_ts_start, i_ts_end;
272 #ifdef INPUT_LIFO_PES_NETLIST
275 int i_pes_start, i_pes_end;
281 /******************************************************************************
283 ******************************************************************************
284 * This structure includes all the local static variables of an input thread,
285 * including the netlist and the ES descriptors
286 * Note that p_es must be defined as a static table, otherwise we would have to
287 * update all reference to it each time the table would be reallocated
288 ******************************************************************************/
290 /* Function pointers used in structure */
291 typedef int (input_open_t) ( p_input_thread_t p_input );
292 typedef int (input_read_t) ( p_input_thread_t p_input, const struct iovec *p_vector,
294 typedef void (input_close_t) ( p_input_thread_t p_input );
297 typedef struct input_thread_s
299 /* Thread properties and locks */
300 boolean_t b_die; /* 'die' flag */
301 boolean_t b_error; /* deadlock */
302 vlc_thread_t thread_id; /* id for thread functions */
303 vlc_mutex_t programs_lock; /* programs modification lock */
304 vlc_mutex_t es_lock; /* es modification lock */
305 int * pi_status; /* temporary status flag */
307 /* Input method description */
308 int i_method; /* input method */
309 int i_handle; /* file/socket descriptor */
310 char * psz_source; /* source */
311 int i_port; /* port number */
312 int i_vlan; /* id for vlan method */
313 input_open_t * p_Open; /* opener of the method */
314 input_read_t * p_Read; /* reading function */
315 input_close_t * p_Close; /* destroying function */
317 /* General stream description */
318 stream_descriptor_t * p_stream; /* PAT tables */
319 es_descriptor_t p_es[INPUT_MAX_ES]; /* carried elementary streams */
320 pcr_descriptor_t * p_pcr; /* PCR struct used for synchronisation */
322 /* List of streams to demux */
323 es_descriptor_t * pp_selected_es[INPUT_MAX_SELECTED_ES];
326 input_netlist_t netlist; /* see above */
328 /* Default settings for spawned decoders */
329 p_aout_thread_t p_aout; /* audio output thread structure */
330 p_vout_thread_t p_vout; /* video output thread */
334 count_t c_loops; /* number of loops */
335 count_t c_bytes; /* bytes read */
336 count_t c_payload_bytes; /* payload useful bytes */
337 count_t c_packets_read; /* packets read */
338 count_t c_packets_trashed; /* trashed packets */
343 #define INPUT_METHOD_NONE 0 /* input thread is inactive */
344 #define INPUT_METHOD_TS_FILE 10 /* TS stream is read from a file */
345 #define INPUT_METHOD_TS_UCAST 20 /* TS UDP unicast */
346 #define INPUT_METHOD_TS_MCAST 21 /* TS UDP multicast */
347 #define INPUT_METHOD_TS_BCAST 22 /* TS UDP broadcast */
348 #define INPUT_METHOD_TS_VLAN_BCAST 32 /* TS UDP broadcast with VLANs */
350 /*****************************************************************************
352 *****************************************************************************/
353 input_thread_t *input_CreateThread ( int i_method, char *psz_source, int i_port,
354 int i_vlan, p_vout_thread_t p_vout,
355 p_aout_thread_t p_aout, int *pi_status );
356 void input_DestroyThread ( input_thread_t *p_input, int *pi_status );
359 int input_OpenAudioStream ( input_thread_t *p_input, int i_pid );
360 void input_CloseAudioStream ( input_thread_t *p_input, int i_pid );
361 int input_OpenVideoStream ( input_thread_t *p_input, int i_pid );
362 void input_CloseVideoStream ( input_thread_t *p_input, int i_pid );