]> git.sesse.net Git - vlc/blob - include/input.h
* Modification de l'input afin de spawner un d�codeur ac3 lorsqu'un tel flux
[vlc] / include / input.h
1 /******************************************************************************
2  * input.h: input thread interface
3  * (c)1999 VideoLAN
4  ******************************************************************************/
5
6 /* needs : "netlist.h", "config.h", "mtime.h" */
7
8 /* ?? missing: 
9  *              tables version control */
10
11 /******************************************************************************
12  * External structures
13  ******************************************************************************
14  * These structures, required here only as pointers destinations, are declared 
15  * in other headers.
16  ******************************************************************************/
17 struct video_cfg_s;                         /* video configuration descriptor */
18 struct vout_thread_s;                                  /* video output thread */
19 struct stream_descriptor_s;                                     /* PSI tables */
20
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 */
27
28 /******************************************************************************
29  * ts_packet_t
30  ******************************************************************************
31  * Describe a TS packet.
32  ******************************************************************************/
33 typedef struct ts_packet_struct
34 {
35     /* Nothing before this line, the code relies on that */
36     byte_t                  buffer[TS_PACKET_SIZE];     /* raw TS data packet */
37
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 ? :-) */
42
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;
46 } ts_packet_t;
47
48
49 /******************************************************************************
50  * pes_packet_t
51  ******************************************************************************
52  * Describes an PES packet, with its properties, and pointers to the TS packets
53  * containing it.
54  ******************************************************************************/
55 typedef struct
56 {
57     /* PES properties */
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.
67               */
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 */
71
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 */
76
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). */
83 } pes_packet_t;
84
85
86 /******************************************************************************
87  * psi_section_t
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  ******************************************************************************/
92 typedef struct
93 {
94     byte_t        buffer[PSI_SECTION_SIZE];
95   
96     boolean_t     b_running_section;    /* Is there a section being decoded ? */
97
98     u16 i_length;
99     u16 i_current_position;
100 } psi_section_t;
101
102
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  ******************************************************************************/
109 typedef struct
110 {   
111     u16                     i_id;            /* stream ID, PID for TS streams */
112     u8                      i_type;                            /* stream type */
113
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
118      * PCR presence */
119     boolean_t               b_psi;  /* does the stream have to be handled by the
120                                                                 PSI decoder ? */
121     /* Markers */
122     int                     i_continuity_counter;
123     boolean_t               b_discontinuity;
124     boolean_t               b_random;
125
126     /* PES packets */
127     pes_packet_t *          p_pes_packet;
128                                        /* current PES packet we are gathering */
129
130     /* PSI packets */
131     psi_section_t *         p_psi_section;           /* idem for a PSI stream */
132
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
137                                         * casts. */
138
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 ? */
145
146 #ifdef STATS
147     /* Stats */
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 */
153 #endif
154 } es_descriptor_t;
155
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 */
161
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            0x81
168
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  ******************************************************************************/
175 typedef struct
176 {
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 */
182
183     int i_es_number;
184     es_descriptor_t **      ap_es;                 /* array of pointers to ES */
185
186 #ifdef DVB_EXTENSIONS
187     /* Service Descriptor (program name) */
188     u8                      i_srv_type;
189     char*                   psz_srv_name;
190 #endif
191
192     /* ?? target background grid descriptor ? */
193     /* ?? video window descriptor ? */
194     /* ?? ISO 639 language descriptor ? */
195
196 #ifdef STATS
197     /* Stats */
198     /* ?? ...stats */
199 #endif
200 } pgrm_descriptor_t;
201
202 /******************************************************************************
203  * pcr_descriptor_t
204  ******************************************************************************
205  * Contains informations used to synchronise the decoder with the server
206  ******************************************************************************/
207
208 typedef struct pcr_descriptor_struct
209 {
210     /* system_date = PTS_date + delta_pcr + delta_absolute */
211     mtime_t                 delta_pcr;
212     mtime_t                 delta_absolute;
213
214     mtime_t                 last_pcr;
215
216     u32                     i_synchro_state;
217     count_t                 c_average_count;
218                             /* counter used to compute dynamic average values */
219 } pcr_descriptor_t;
220
221 /******************************************************************************
222  * stream_descriptor_t
223  ******************************************************************************
224  * Describes a transport stream and list its associated programs. Build upon
225  * the informations carried in program association sections
226  ******************************************************************************/
227 typedef struct
228 {
229     u16                     i_stream_id;                         /* stream id */
230
231     /* Program Association Table status */
232     u8                      i_PAT_version;                  /* version number */ 
233     boolean_t               b_is_PAT_complete;        /* Is the PAT complete ?*/
234     u8                      i_known_PAT_sections;
235                                       /* Number of section we received so far */
236     byte_t                  a_known_PAT_sections[32];
237                                                  /* Already received sections */
238
239     /* Program Map Table status */
240     boolean_t               b_is_PMT_complete;        /* Is the PMT complete ?*/
241     u8                      i_known_PMT_sections;
242                                       /* Number of section we received so far */
243     byte_t                  a_known_PMT_sections[32];
244                                                  /* Already received sections */
245
246     /* Service Description Table status */
247     u8                      i_SDT_version;                  /* version number */ 
248     boolean_t               b_is_SDT_complete;        /* Is the SDT complete ?*/
249     u8                      i_known_SDT_sections;
250                                       /* Number of section we received so far */
251     byte_t                  a_known_SDT_sections[32];
252                                                  /* Already received sections */
253
254     /* Programs description */
255     int i_pgrm_number;                    /* Number of program number we have */
256     pgrm_descriptor_t **    ap_programs;         /* Array of pointers to pgrm */
257
258 #ifdef STATS
259     /* Stats */
260     /* ?? ...stats */
261 #endif
262 } stream_descriptor_t;
263
264 /******************************************************************************
265  * input_netlist_t
266  ******************************************************************************/
267 typedef struct
268 {
269     vlc_mutex_t             lock;                /* netlist modification lock */
270     struct iovec            p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
271                                            /* FIFO or LIFO of free TS packets */
272     ts_packet_t *           p_ts_packets;
273                                /* pointer to the first TS packet we allocated */
274
275     pes_packet_t *          p_pes_free[INPUT_MAX_PES + 1];
276                                           /* FIFO or LIFO of free PES packets */
277     pes_packet_t *          p_pes_packets;
278                               /* pointer to the first PES packet we allocated */
279
280     /* To use the efficiency of the scatter/gather IO operations. We implemented
281      * it in 2 ways, as we don't know yet which one is better : as a FIFO (code
282      * simplier) or as a LIFO stack (when we doesn't care of the ordering, this
283      * allow to drastically improve the cache performance) */
284 #ifdef INPUT_LIFO_TS_NETLIST
285     int                     i_ts_index;
286 #else
287     int                     i_ts_start, i_ts_end;
288 #endif
289 #ifdef INPUT_LIFO_PES_NETLIST
290     int                     i_pes_index;
291 #else
292     int                     i_pes_start, i_pes_end;
293 #endif
294 } input_netlist_t;
295
296 /******************************************************************************
297  * input_thread_t
298  ******************************************************************************
299  * This structure includes all the local static variables of an input thread,
300  * including the netlist and the ES descriptors
301  * Note that p_es must be defined as a static table, otherwise we would have to
302  * update all reference to it each time the table would be reallocated 
303  ******************************************************************************/
304
305 /* function pointers */
306 struct input_thread_s;
307 struct input_cfg_s;
308 typedef int (*f_open_t)( struct input_thread_s *, struct input_cfg_s *);
309 typedef int (*f_read_t)( struct input_thread_s *, const struct iovec *,
310                          size_t );
311 typedef void (*f_clean_t)( struct input_thread_s * );
312
313 typedef struct input_thread_s
314 {
315     /* Thread properties and locks */
316     boolean_t               b_die;                              /* 'die' flag */
317     boolean_t               b_error;                              /* deadlock */
318     vlc_thread_t            thread_id;             /* id for thread functions */
319     vlc_mutex_t             programs_lock;      /* programs modification lock */
320     vlc_mutex_t             es_lock;                  /* es modification lock */
321
322     /* Input method description */
323     int                     i_method;                         /* input method */
324     int                     i_handle;               /* file/socket descriptor */
325     int                     i_vlan_id;                  /* id for vlan method */
326     f_open_t                p_open;    /* pointer to the opener of the method */
327     f_read_t                p_read;        /* pointer to the reading function */
328     f_clean_t               p_clean;    /* pointer to the destroying function */
329
330     /* General stream description */
331     stream_descriptor_t *   p_stream;                           /* PAT tables */
332     es_descriptor_t         p_es[INPUT_MAX_ES]; /* carried elementary streams */
333     pcr_descriptor_t *      p_pcr;     /* PCR struct used for synchronisation */
334
335     /* List of streams to demux */
336     es_descriptor_t *       pp_selected_es[INPUT_MAX_SELECTED_ES];
337     
338     /* Netlists */
339     input_netlist_t         netlist;                             /* see above */
340
341     /* ?? default settings for new decoders */
342     struct aout_thread_s *      p_aout;      /* audio output thread structure */
343
344 #ifdef STATS
345     /* Stats */
346     count_t                 c_loops;                       /* number of loops */
347     count_t                 c_bytes;                   /* total of bytes read */
348     count_t                 c_payload_bytes; /* total of payload useful bytes */
349     count_t                 c_ts_packets_read;       /* total of packets read */
350     count_t                 c_ts_packets_trashed; /* total of trashed packets */
351     /* ?? ... other stats */
352 #endif
353 } input_thread_t;
354
355 /* Input methods */
356 #define INPUT_METHOD_NONE           0             /* input thread is inactive */
357 #define INPUT_METHOD_TS_FILE       10        /* TS stream is read from a file */
358 #define INPUT_METHOD_TS_UCAST      20                       /* TS UDP unicast */
359 #define INPUT_METHOD_TS_MCAST      21                     /* TS UDP multicast */
360 #define INPUT_METHOD_TS_BCAST      22                     /* TS UDP broadcast */
361 #define INPUT_METHOD_TS_VLAN_BCAST 32          /* TS UDP broadcast with VLANs */
362
363 /******************************************************************************
364  * input_cfg_t: input thread configuration structure
365  ******************************************************************************
366  * This structure is passed as a parameter to input_CreateTtread(). It includes
367  * several fields describing potential properties of a new object. 
368  * The 'i_properties' field allow to set only a subset of the required 
369  * properties, asking the called function to use default settings for
370  * the other ones.
371  ******************************************************************************/
372 typedef struct input_cfg_s
373 {
374     u64     i_properties;
375
376     /* Input method properties */
377     int     i_method;                                         /* input method */
378     char *  psz_filename;                                         /* filename */
379     char *  psz_hostname;                                  /* server hostname */
380     char *  psz_ip;                                              /* server IP */
381     int     i_port;                                                   /* port */
382     int     i_vlan;                                            /* vlan number */
383
384     /* ??... default settings for new decoders */
385     struct aout_thread_s *      p_aout;      /* audio output thread structure */
386
387 } input_cfg_t;
388
389 /* Properties flags */
390 #define INPUT_CFG_METHOD    (1 << 0)
391 #define INPUT_CFG_FILENAME  (1 << 4)
392 #define INPUT_CFG_HOSTNAME  (1 << 8)
393 #define INPUT_CFG_IP        (1 << 9)
394 #define INPUT_CFG_PORT      (1 << 10)
395 #define INPUT_CFG_VLAN      (1 << 11)
396
397 /*****************************************************************************
398  * Prototypes
399  *****************************************************************************/
400 input_thread_t *input_CreateThread      ( input_cfg_t *p_cfg );
401 void            input_DestroyThread     ( input_thread_t *p_input );
402
403 int             input_OpenAudioStream   ( input_thread_t *p_input, int i_pid
404                                           /* ?? , struct audio_cfg_s * p_cfg */ );
405 void            input_CloseAudioStream  ( input_thread_t *p_input, int i_pid );
406 int             input_OpenVideoStream   ( input_thread_t *p_input, 
407                                           struct vout_thread_s *p_vout, struct video_cfg_s * p_cfg );
408 void            input_CloseVideoStream  ( input_thread_t *p_input, int i_pid );
409
410 /* ?? settings functions */
411 /* ?? info functions */