]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
Second step in area management ; everything is in place now to have
[vlc] / include / input_ext-intf.h
1 /*****************************************************************************
2  * input_ext-intf.h: structures of the input exported to the interface
3  * This header provides structures to read the stream descriptors and
4  * control the pace of reading. 
5  *****************************************************************************
6  * Copyright (C) 1999, 2000 VideoLAN
7  * $Id: input_ext-intf.h,v 1.24 2001/02/20 08:47:24 stef Exp $
8  *
9  * Authors: Christophe Massiot <massiot@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*
27  * Communication input -> interface
28  */
29 #define INPUT_MAX_PLUGINS   1
30 /* FIXME ! */
31 #define REQUESTED_MPEG         1
32 #define REQUESTED_AC3          2
33 #define REQUESTED_LPCM         3
34 #define REQUESTED_NOAUDIO    255
35
36 /*****************************************************************************
37  * es_descriptor_t: elementary stream descriptor
38  *****************************************************************************
39  * Describes an elementary stream, and includes fields required to handle and
40  * demultiplex this elementary stream.
41  *****************************************************************************/
42 struct decoder_fifo_s;                         /* defined in input_ext-dec.h */
43 struct pgrm_descriptor_s;
44
45 typedef struct es_descriptor_s
46 {
47     u16                     i_id;            /* stream ID for PS, PID for TS */
48     u8                      i_stream_id;     /* stream ID defined in the PES */
49     u8                      i_type;                           /* stream type */
50     boolean_t               b_audio;      /* is the stream an audio stream that
51                                            * will need to be discarded with
52                                            * fast forward and slow motion ?  */
53     char                    psz_desc[20]; /* description of ES: audio language
54                                            * for instance ; NULL if not
55                                            *  available */
56
57     /* Demultiplexer information */
58     void *                  p_demux_data;
59     struct pgrm_descriptor_s *
60                             p_pgrm;  /* very convenient in the demultiplexer */
61
62     /* PES parser information */
63     struct pes_packet_s *   p_pes;                            /* Current PES */
64     struct data_packet_s *  p_last;   /* The last packet gathered at present */
65     int                     i_pes_real_size;   /* as indicated by the header */
66
67     /* Decoder information */
68     struct decoder_fifo_s * p_decoder_fifo;
69     vlc_thread_t            thread_id;                  /* ID of the decoder */
70
71 #ifdef STATS
72     count_t                 c_payload_bytes;/* total of payload useful bytes */
73     count_t                 c_packets;                 /* total packets read */
74     count_t                 c_invalid_packets;       /* invalid packets read */
75 #endif
76 } es_descriptor_t;
77
78 /* Special PID values - note that the PID is only on 13 bits, and that values
79  * greater than 0x1fff have no meaning in a stream */
80 #define PROGRAM_ASSOCIATION_TABLE_PID   0x0000
81 #define CONDITIONNAL_ACCESS_TABLE_PID   0x0001                   /* not used */
82 #define EMPTY_ID                        0xffff    /* empty record in a table */
83  
84 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
85 #define MPEG1_VIDEO_ES      0x01
86 #define MPEG2_VIDEO_ES      0x02
87 #define MPEG1_AUDIO_ES      0x03
88 #define MPEG2_AUDIO_ES      0x04
89 #define AC3_AUDIO_ES        0x81
90 /* These ones might violate the norm : */
91 #define DVD_SPU_ES          0x82
92 #define LPCM_AUDIO_ES       0x83
93 #define UNKNOWN_ES          0xFF
94
95 /*****************************************************************************
96  * pgrm_descriptor_t
97  *****************************************************************************
98  * Describes a program and list associated elementary streams. It is build by
99  * the PSI decoder upon the informations carried in program map sections
100  *****************************************************************************/
101 typedef struct pgrm_descriptor_s
102 {
103     /* Program characteristics */
104     u16                     i_number;                      /* program number */
105     u8                      i_version;                     /* version number */
106     boolean_t               b_is_ok;      /* Is the description up to date ? */
107
108     /* Service Descriptor (program name) - DVB extension */
109     u8                      i_srv_type;
110     char *                  psz_srv_name;
111
112     /* Synchronization information */
113     mtime_t                 delta_cr;
114     mtime_t                 cr_ref, sysdate_ref;
115     mtime_t                 last_cr; /* reference to detect unexpected stream
116                                       * discontinuities                      */
117     count_t                 c_average_count;
118                            /* counter used to compute dynamic average values */
119     int                     i_synchro_state;
120
121     /* Demultiplexer data */
122     void *                  p_demux_data;
123
124     /* Decoders control */
125     struct vout_thread_s *  p_vout;
126     struct aout_thread_s *  p_aout;
127
128     int                     i_es_number;      /* size of the following array */
129     es_descriptor_t **      pp_es;                /* array of pointers to ES */
130 } pgrm_descriptor_t;
131
132 /* Synchro states */
133 #define SYNCHRO_OK          0
134 #define SYNCHRO_START       1
135 #define SYNCHRO_REINIT      2
136
137 /*****************************************************************************
138  * input_area_t
139  *****************************************************************************
140  * Attributes for current area (title for DVD)
141  *****************************************************************************/
142 typedef struct input_area_s
143 {
144     /* selected area attributes */
145     int                     i_id;        /* identificator for area */
146     off_t                   i_start;     /* start offset of area */
147     off_t                   i_size;      /* total size of the area
148                                           * (in arbitrary units) */
149
150     /* navigation parameters */
151     off_t                   i_tell;      /* actual location in the area
152                                           * (in arbitrary units) */
153     off_t                   i_seek;      /* next requested location
154                                           * (changed by the interface thread */
155
156     /* area subdivision */
157     int                     i_part_nb;   /* number of parts (chapter for DVD)*/
158     int                     i_part;      /* currently selected part */
159
160     /* offset to plugin related data */
161     off_t                   i_plugin_data;
162 } input_area_t;
163
164 /*****************************************************************************
165  * stream_descriptor_t
166  *****************************************************************************
167  * Describes a stream and list its associated programs. Build upon
168  * the information carried in program association sections (for instance)
169  *****************************************************************************/
170 typedef struct stream_descriptor_s
171 {
172     u16                     i_stream_id;                        /* stream id */
173     vlc_mutex_t             stream_lock;  /* to be taken every time you read
174                                            * or modify stream, pgrm or es    */
175
176     /* Input method data */
177     boolean_t               b_pace_control;    /* can we read when we want ? */
178     boolean_t               b_seekable;               /* can we do lseek() ? */
179
180     /* if (b_seekable) : */
181     int                     i_area_nb;
182     input_area_t **         pp_areas;      /* list of areas in stream == offset
183                                             * interval with own properties */
184     input_area_t *          p_selected_area;
185     u32                     i_mux_rate; /* the rate we read the stream (in
186                                          * units of 50 bytes/s) ; 0 if undef */
187
188     /* New status and rate requested by the interface */
189     int                     i_new_status, i_new_rate;
190     vlc_cond_t              stream_wait; /* interface -> input in case of a
191                                           * status change request            */
192
193     /* Demultiplexer data */
194     void *                  p_demux_data;
195
196     /* Programs descriptions */
197     int                     i_pgrm_number;    /* size of the following array */
198     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
199
200     /* ES descriptions */
201     int                     i_es_number;
202     es_descriptor_t **      pp_es;             /* carried elementary streams */
203     int                     i_selected_es_number;
204     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
205
206     /* Stream control */
207     stream_ctrl_t           control;
208 } stream_descriptor_t;
209
210 /*****************************************************************************
211  * i_p_config_t
212  *****************************************************************************
213  * This structure gives plugins pointers to the useful functions of input
214  *****************************************************************************/
215 struct input_thread_s;
216 struct data_packet_s;
217 struct es_descriptor_s;
218
219 typedef struct i_p_config_s
220 {
221     int                 (* pf_peek_stream)( struct input_thread_s *,
222                                             byte_t * buffer, size_t );
223     void                (* pf_demux_pes)( struct input_thread_s *,
224                                           struct data_packet_s *,
225                                           struct es_descriptor_s *,
226                                           boolean_t b_unit_start,
227                                           boolean_t b_packet_lost );
228 } i_p_config_t;
229
230 /*****************************************************************************
231  * input_thread_t
232  *****************************************************************************
233  * This structure includes all the local static variables of an input thread
234  *****************************************************************************/
235 struct aout_thread_s;
236 struct vout_thread_s;
237
238 typedef struct input_thread_s
239 {
240     /* Thread properties and locks */
241     boolean_t               b_die;                             /* 'die' flag */
242     boolean_t               b_error;
243     boolean_t               b_eof;
244     vlc_thread_t            thread_id;            /* id for thread functions */
245     int *                   pi_status;              /* temporary status flag */
246
247     /* Input module */
248     struct module_s *       p_input_module;
249
250     /* Init/End */
251     void                 (* pf_init)( struct input_thread_s * );
252     void                 (* pf_open)( struct input_thread_s * );
253     void                 (* pf_close)( struct input_thread_s * );
254     void                 (* pf_end)( struct input_thread_s * );
255
256     /* Read & Demultiplex */
257     int                  (* pf_read)( struct input_thread_s *,
258                                       struct data_packet_s * pp_packets[] );
259     void                 (* pf_demux)( struct input_thread_s *,
260                                        struct data_packet_s * );
261
262     /* Packet management facilities */
263     struct data_packet_s *(*pf_new_packet)( void *, size_t );
264     struct pes_packet_s *(* pf_new_pes)( void * );
265     void                 (* pf_delete_packet)( void *,
266                                                struct data_packet_s * );
267     void                 (* pf_delete_pes)( void *, struct pes_packet_s * );
268
269     /* Stream control capabilities */
270     int                  (* pf_rewind)( struct input_thread_s * );
271                                            /* NULL if we don't support going *
272                                             * backwards (it's gonna be fun)  */
273     void                 (* pf_seek)( struct input_thread_s *, off_t );
274
275     i_p_config_t            i_p_config;              /* plugin configuration */
276     char *                  p_source;
277
278     int                     i_handle;           /* socket or file descriptor */
279     void *                  p_method_data;     /* data of the packet manager */
280     void *                  p_plugin_data;             /* data of the plugin */
281
282     /* General stream description */
283     stream_descriptor_t     stream;                            /* PAT tables */
284
285     /* For auto-launch of decoders */
286     struct aout_thread_s *  p_default_aout;
287     struct vout_thread_s *  p_default_vout;
288
289 #ifdef STATS
290     count_t                 c_loops;
291     count_t                 c_bytes;                           /* bytes read */
292     count_t                 c_payload_bytes;         /* payload useful bytes */
293     count_t                 c_packets_read;                  /* packets read */
294     count_t                 c_packets_trashed;            /* trashed packets */
295 #endif
296 } input_thread_t;
297
298
299 /*
300  * Communication interface -> input
301  */
302
303 /*****************************************************************************
304  * input_config_t
305  *****************************************************************************
306  * This structure is given by the interface to an input thread
307  *****************************************************************************/
308 typedef struct input_config_s
309 {
310     /* Input method description */
311     int                         i_method;                    /* input method */
312     char *                      p_source;                          /* source */
313
314     /* For auto-launch of decoders */
315     struct aout_thread_s *      p_default_aout;
316     struct vout_thread_s *      p_default_vout;
317 } input_config_t;
318
319 /* Input methods */
320 #define INPUT_METHOD_NONE           0            /* input thread is inactive */
321 #define INPUT_METHOD_FILE          10   /* stream is read from file p_source */
322 #define INPUT_METHOD_DVD           11      /* stream is read from dvd device */
323 #define INPUT_METHOD_UCAST         20                         /* UDP unicast */
324 #define INPUT_METHOD_MCAST         21                       /* UDP multicast */
325 #define INPUT_METHOD_BCAST         22                       /* UDP broadcast */
326 #define INPUT_METHOD_VLAN_BCAST    32            /* UDP broadcast with VLANs */
327
328 /* Status changing methods */
329 #define INPUT_STATUS_END            0
330 #define INPUT_STATUS_PLAY           1
331 #define INPUT_STATUS_PAUSE          2
332 #define INPUT_STATUS_FASTER         3
333 #define INPUT_STATUS_SLOWER         4
334
335 /*****************************************************************************
336  * Prototypes
337  *****************************************************************************/
338 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
339                                              int *pi_status );
340 void input_DestroyThread( struct input_thread_s *, int *pi_status );
341
342 void input_SetStatus( struct input_thread_s *, int );
343 void input_SetRate  ( struct input_thread_s *, int );
344 void input_Seek     ( struct input_thread_s *, off_t );
345