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