]> git.sesse.net Git - vlc/blob - include/input.h
. suppression d'une variable inutile que j'avais laiss�e trainer
[vlc] / include / input.h
1 /*****************************************************************************
2  * input.h: input thread interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Constants related to input
26  *****************************************************************************/
27 #define TS_PACKET_SIZE      188                       /* size of a TS packet */
28 #define PES_HEADER_SIZE     14     /* size of the first part of a PES header */
29 #define PSI_SECTION_SIZE    4096            /* Maximum size of a PSI section */
30
31 /*****************************************************************************
32  * ts_packet_t
33  *****************************************************************************
34  * Describe a TS packet.
35  *****************************************************************************/
36 typedef struct ts_packet_s
37 {
38     /* Nothing before this line, the code relies on that */
39     byte_t                  buffer[TS_PACKET_SIZE];    /* raw TS data packet */
40
41     /* Decoders information */
42     unsigned int            i_payload_start;
43                                   /* start of the PES payload in this packet */
44     unsigned int            i_payload_end;                    /* guess ? :-) */
45
46     /* Used to chain the TS packets that carry data for a same PES or PSI */
47     struct ts_packet_s      *  p_prev_ts;
48     struct ts_packet_s      *  p_next_ts;
49 } ts_packet_t;
50
51 /*****************************************************************************
52  * pes_packet_t
53  *****************************************************************************
54  * Describes an PES packet, with its properties, and pointers to the TS packets
55  * containing it.
56  *****************************************************************************/
57 typedef struct pes_packet_s
58 {
59     /* PES properties */
60     boolean_t               b_data_loss;  /* The previous (at least) PES packet
61            * has been lost. The decoders will have to find a way to recover. */
62     boolean_t               b_data_alignment;  /* used to find the beginning of
63                                                 * a video or audio unit      */
64     boolean_t               b_has_pts;       /* is the following field set ? */
65     mtime_t                 i_pts; /* the PTS for this packet (if set above) */
66     boolean_t               b_random_access;
67             /* if TRUE, in the payload of this packet, there is the first byte
68              * of a video sequence header, or the first byte of an audio frame.
69              */
70     u8                      i_stream_id;              /* payload type and id */
71     int                     i_pes_size;    /* size of the current PES packet */
72     int                     i_pes_real_size;      /* real size of the current
73                                                    * PES packet, ie. the one
74                                                    * announced in the header */
75     int                     i_ts_packets;/* number of TS packets in this PES */
76
77     /* Demultiplexer environment */
78     boolean_t               b_discard_payload;  /* is the packet messed up ? */
79     byte_t *                p_pes_header;       /* pointer to the PES header */
80     byte_t *                p_pes_header_save;           /* temporary buffer */
81
82     /* Pointers to TS packets (TS packets are then linked by the p_prev_ts and
83        p_next_ts fields of the ts_packet_t struct) */
84     ts_packet_t *           p_first_ts;   /* The first TS packet containing this
85                                            * PES (used by decoders). */
86     ts_packet_t *           p_last_ts; /* The last TS packet gathered at present
87                                         * (used by the demultiplexer). */
88 } pes_packet_t;
89
90 /*****************************************************************************
91  * psi_section_t
92  *****************************************************************************
93  * Describes a PSI section. Beware, it doesn't contain pointers to the TS
94  * packets that contain it as for a PES, but the data themselves
95  *****************************************************************************/
96 typedef struct psi_section_s
97 {
98     byte_t        buffer[PSI_SECTION_SIZE];
99
100     boolean_t     b_running_section;   /* Is there a section being decoded ? */
101
102     u16 i_length;
103     u16 i_current_position;
104 } psi_section_t;
105
106
107 /*****************************************************************************
108  * es_descriptor_t: elementary stream descriptor
109  *****************************************************************************
110  * Describes an elementary stream, and includes fields required to handle and
111  * demultiplex this elementary stream.
112  *****************************************************************************/
113 typedef struct es_descriptor_t
114 {
115     u16                     i_id;           /* stream ID, PID for TS streams */
116     u8                      i_type;                           /* stream type */
117
118     boolean_t               b_pcr;        /* does the stream include a PCR ? */
119     /* XXX?? b_pcr will be replaced by something else: since a PCR can't be shared
120      * between several ES, we will probably store the PCR fields directly here,
121      * and one of those fields will probably (again) be used as a test of the
122      * PCR presence */
123     boolean_t               b_psi;  /* does the stream have to be handled by the
124                                                                 PSI decoder ? */
125     /* Markers */
126     int                     i_continuity_counter;
127     boolean_t               b_discontinuity;
128     boolean_t               b_random;
129
130     /* PES packets */
131     pes_packet_t *          p_pes_packet;
132                                       /* current PES packet we are gathering */
133
134     /* PSI packets */
135     psi_section_t *         p_psi_section;          /* idem for a PSI stream */
136
137     /* Decoder informations */
138     void *                  p_dec;     /* p_dec is void *, since we don't know a
139                                         * priori whether it is adec_thread_t or
140                                         * vdec_thread_t. We will use explicit
141                                         * casts. */
142
143     /* XXX?? video stream descriptor ? */
144     /* XXX?? audio stream descriptor ? */
145     /* XXX?? hierarchy descriptor ? */
146     /* XXX?? target background grid descriptor ? */
147     /* XXX?? video window descriptor ? */
148     /* XXX?? ISO 639 language descriptor ? */
149
150 #ifdef STATS
151     /* Stats */
152     count_t                 c_bytes;                     /* total bytes read */
153     count_t                 c_payload_bytes;/* total of payload useful bytes */
154     count_t                 c_packets;                 /* total packets read */
155     count_t                 c_invalid_packets;       /* invalid packets read */
156     /* XXX?? ... other stats */
157 #endif
158 } es_descriptor_t;
159
160 /* Special PID values - note that the PID is only on 13 bits, and that values
161  * greater than 0x1fff have no meaning in a stream */
162 #define PROGRAM_ASSOCIATION_TABLE_PID   0x0000
163 #define CONDITIONNAL_ACCESS_TABLE_PID   0x0001                   /* not used */
164 #define EMPTY_PID                       0xffff    /* empty record in a table */
165
166 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
167 #define MPEG1_VIDEO_ES          0x01
168 #define MPEG2_VIDEO_ES          0x02
169 #define MPEG1_AUDIO_ES          0x03
170 #define MPEG2_AUDIO_ES          0x04
171 #define AC3_AUDIO_ES            0x81
172 #define DVD_SPU_ES             0x82           /* 0x82 might violate the norm */
173
174 /*****************************************************************************
175  * program_descriptor_t
176  *****************************************************************************
177  * Describes a program and list associated elementary streams. It is build by
178  * the PSI decoder upon the informations carried in program map sections
179  *****************************************************************************/
180 typedef struct
181 {
182     /* Program characteristics */
183     u16                     i_number;                      /* program number */
184     u8                      i_version;                     /* version number */
185     boolean_t               b_is_ok;       /* Is the description up to date ?*/
186     u16                     i_pcr_pid;                             /* PCR ES */
187
188     int i_es_number;
189     es_descriptor_t **      ap_es;                /* array of pointers to ES */
190
191 #ifdef DVB_EXTENSIONS
192     /* Service Descriptor (program name) */
193     u8                      i_srv_type;
194     char*                   psz_srv_name;
195 #endif
196
197     /* XXX?? target background grid descriptor ? */
198     /* XXX?? video window descriptor ? */
199     /* XXX?? ISO 639 language descriptor ? */
200
201 #ifdef STATS
202     /* Stats */
203     /* XXX?? ...stats */
204 #endif
205 } pgrm_descriptor_t;
206
207 /*****************************************************************************
208  * pcr_descriptor_t
209  *****************************************************************************
210  * Contains informations used to synchronise the decoder with the server
211  *****************************************************************************/
212
213 typedef struct pcr_descriptor_struct
214 {
215     /* system_date = PTS_date + delta_pcr + delta_absolute */
216     mtime_t                 delta_pcr;
217     mtime_t                 delta_absolute;
218
219     mtime_t                 last_pcr;
220
221     u32                     i_synchro_state;
222     count_t                 c_average_count;
223                            /* counter used to compute dynamic average values */
224 } pcr_descriptor_t;
225
226 /*****************************************************************************
227  * stream_descriptor_t
228  *****************************************************************************
229  * Describes a transport stream and list its associated programs. Build upon
230  * the informations carried in program association sections
231  *****************************************************************************/
232 typedef struct
233 {
234     u16                     i_stream_id;                        /* stream id */
235
236     /* Program Association Table status */
237     u8                      i_PAT_version;                 /* version number */
238     boolean_t               b_is_PAT_complete;       /* Is the PAT complete ?*/
239     u8                      i_known_PAT_sections;
240                                      /* Number of section we received so far */
241     byte_t                  a_known_PAT_sections[32];
242                                                 /* Already received sections */
243
244     /* Program Map Table status */
245     boolean_t               b_is_PMT_complete;       /* Is the PMT complete ?*/
246     u8                      i_known_PMT_sections;
247                                      /* Number of section we received so far */
248     byte_t                  a_known_PMT_sections[32];
249                                                 /* Already received sections */
250
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;
255                                      /* Number of section we received so far */
256     byte_t                  a_known_SDT_sections[32];
257                                                 /* Already received sections */
258
259     /* Programs description */
260     int i_pgrm_number;                   /* Number of program number we have */
261     pgrm_descriptor_t **    ap_programs;        /* Array of pointers to pgrm */
262
263 #ifdef STATS
264     /* Stats */
265     /* XXX?? ...stats */
266 #endif
267 } stream_descriptor_t;
268
269 /*****************************************************************************
270  * input_netlist_t
271  *****************************************************************************/
272 typedef struct
273 {
274     vlc_mutex_t             lock;               /* netlist modification lock */
275     struct iovec            p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
276                                           /* FIFO or LIFO of free TS packets */
277     ts_packet_t *           p_ts_packets;
278                               /* pointer to the first TS packet we allocated */
279
280     pes_packet_t *          p_pes_free[INPUT_MAX_PES + 1];
281                                          /* FIFO or LIFO of free PES packets */
282     pes_packet_t *          p_pes_packets;
283                              /* pointer to the first PES packet we allocated */
284
285     /* To use the efficiency of the scatter/gather IO operations. We implemented
286      * it in 2 ways, as we don't know yet which one is better : as a FIFO (code
287      * simplier) or as a LIFO stack (when we doesn't care of the ordering, this
288      * allow to drastically improve the cache performance) */
289 #ifdef INPUT_LIFO_TS_NETLIST
290     int                     i_ts_index;
291 #else
292     int                     i_ts_start, i_ts_end;
293 #endif
294 #ifdef INPUT_LIFO_PES_NETLIST
295     int                     i_pes_index;
296 #else
297     int                     i_pes_start, i_pes_end;
298 #endif
299 } input_netlist_t;
300
301
302
303 /*****************************************************************************
304  * input_thread_t
305  *****************************************************************************
306  * This structure includes all the local static variables of an input thread,
307  * including the netlist and the ES descriptors
308  * Note that p_es must be defined as a static table, otherwise we would have to
309  * update all reference to it each time the table would be reallocated
310  *****************************************************************************/
311
312 /* Function pointers used in structure */
313 typedef int  (input_open_t)     ( p_input_thread_t p_input );
314 typedef int  (input_read_t)     ( p_input_thread_t p_input, const struct iovec *p_vector,
315                                    size_t i_count );
316 typedef void (input_close_t)    ( p_input_thread_t p_input );
317
318 /* Structure */
319 typedef struct input_thread_s
320 {
321     /* Thread properties and locks */
322     boolean_t                   b_die;                         /* 'die' flag */
323     boolean_t                   b_error;                         /* deadlock */
324     vlc_thread_t                thread_id;        /* id for thread functions */
325     vlc_mutex_t                 programs_lock; /* programs modification lock */
326     vlc_mutex_t                 es_lock;             /* es modification lock */
327     int *                       pi_status;          /* temporary status flag */
328
329     /* Input method description */
330     int                         i_method;                    /* input method */
331     int                         i_handle;          /* file/socket descriptor */
332     char *                      psz_source;                        /* source */
333     int                         i_port;                     /* port number */
334     int                         i_vlan;                /* id for vlan method */
335     input_open_t *              p_Open;              /* opener of the method */
336     input_read_t *              p_Read;                  /* reading function */
337     input_close_t *             p_Close;              /* destroying function */
338
339     /* General stream description */
340     stream_descriptor_t *   p_stream;                          /* PAT tables */
341     es_descriptor_t         p_es[INPUT_MAX_ES];/* carried elementary streams */
342     pcr_descriptor_t *      p_pcr;    /* PCR struct used for synchronisation */
343
344     /* List of streams to demux */
345     es_descriptor_t *       pp_selected_es[INPUT_MAX_SELECTED_ES];
346
347     /* Netlists */
348     input_netlist_t         netlist;                            /* see above */
349
350     /* Default settings for spawned decoders */
351     p_aout_thread_t             p_aout;     /* audio output thread structure */
352     p_vout_thread_t             p_vout;               /* video output thread */
353
354 #ifdef STATS
355     /* Statistics */
356     count_t                     c_loops;                  /* number of loops */
357     count_t                     c_bytes;                       /* bytes read */
358     count_t                     c_payload_bytes;     /* payload useful bytes */
359     count_t                     c_packets_read;              /* packets read */
360     count_t                     c_packets_trashed;        /* trashed packets */
361 #endif
362 } input_thread_t;
363
364 /* Input methods */
365 #define INPUT_METHOD_NONE           0            /* input thread is inactive */
366 #define INPUT_METHOD_TS_FILE       10       /* TS stream is read from a file */
367 #define INPUT_METHOD_TS_UCAST      20                      /* TS UDP unicast */
368 #define INPUT_METHOD_TS_MCAST      21                    /* TS UDP multicast */
369 #define INPUT_METHOD_TS_BCAST      22                    /* TS UDP broadcast */
370 #define INPUT_METHOD_TS_VLAN_BCAST 32         /* TS UDP broadcast with VLANs */
371
372 /*****************************************************************************
373  * Prototypes
374  *****************************************************************************/
375 input_thread_t *input_CreateThread      ( int i_method, char *psz_source, int i_port,
376                                           int i_vlan, p_vout_thread_t p_vout,
377                                           p_aout_thread_t p_aout, int *pi_status );
378 void            input_DestroyThread     ( input_thread_t *p_input, int *pi_status );
379
380
381 int             input_OpenAudioStream   ( input_thread_t *p_input, int i_pid );
382 void            input_CloseAudioStream  ( input_thread_t *p_input, int i_pid );
383 int             input_OpenVideoStream   ( input_thread_t *p_input, int i_pid );
384 void            input_CloseVideoStream  ( input_thread_t *p_input, int i_pid );