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