]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
New --enable-release config option.
[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.44 2001/10/02 16:46:59 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     count_t                 c_packets;                 /* total packets read */
77     count_t                 c_invalid_packets;       /* invalid packets read */
78 } es_descriptor_t;
79
80 /* Special PID values - note that the PID is only on 13 bits, and that values
81  * greater than 0x1fff have no meaning in a stream */
82 #define PROGRAM_ASSOCIATION_TABLE_PID   0x0000
83 #define CONDITIONNAL_ACCESS_TABLE_PID   0x0001                   /* not used */
84 #define EMPTY_ID                        0xffff    /* empty record in a table */
85  
86 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
87 #define MPEG1_VIDEO_ES      0x01
88 #define MPEG2_VIDEO_ES      0x02
89 #define MPEG1_AUDIO_ES      0x03
90 #define MPEG2_AUDIO_ES      0x04
91 #define AC3_AUDIO_ES        0x81
92 /* These ones might violate the norm : */
93 #define DVD_SPU_ES          0x82
94 #define LPCM_AUDIO_ES       0x83
95 #define UNKNOWN_ES          0xFF
96
97 /* ES Categories to be used by interface plugins */
98 #define VIDEO_ES        0x00
99 #define AUDIO_ES        0x01
100 #define SPU_ES          0x02
101 #define NAV_ES          0x03
102 #define UNKNOWN_ES      0xFF
103 /*****************************************************************************
104  * pgrm_descriptor_t
105  *****************************************************************************
106  * Describes a program and list associated elementary streams. It is build by
107  * the PSI decoder upon the informations carried in program map sections
108  *****************************************************************************/
109 typedef struct pgrm_descriptor_s
110 {
111     /* Program characteristics */
112     u16                     i_number;                      /* program number */
113     u8                      i_version;                     /* version number */
114     boolean_t               b_is_ok;      /* Is the description up to date ? */
115
116     /* Service Descriptor (program name) - DVB extension */
117     u8                      i_srv_type;
118     char *                  psz_srv_name;
119
120     /* Synchronization information */
121     mtime_t                 delta_cr;
122     mtime_t                 cr_ref, sysdate_ref;
123     mtime_t                 last_cr; /* reference to detect unexpected stream
124                                       * discontinuities                      */
125     count_t                 c_average_count;
126                            /* counter used to compute dynamic average values */
127     int                     i_synchro_state;
128
129     /* Demultiplexer data */
130     void *                  p_demux_data;
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     int                     i_angle_nb;  /* number of angles/title units */
165     int                     i_angle;
166
167     /* offset to plugin related data */
168     off_t                   i_plugin_data;
169 } input_area_t;
170
171 /*****************************************************************************
172  * stream_descriptor_t
173  *****************************************************************************
174  * Describes a stream and list its associated programs. Build upon
175  * the information carried in program association sections (for instance)
176  *****************************************************************************/
177 typedef struct stream_descriptor_s
178 {
179     u16                     i_stream_id;                        /* stream id */
180     boolean_t               b_changed;    /* if stream has been changed,
181                                              we have to inform the interface */
182     vlc_mutex_t             stream_lock;  /* to be taken every time you read
183                                            * or modify stream, pgrm or es    */
184
185     /* Input method data */
186     int                     i_method;       /* input method for stream: file,
187                                                disc or network */
188     boolean_t               b_pace_control;    /* can we read when we want ? */
189     boolean_t               b_seekable;               /* can we do lseek() ? */
190
191     /* if (b_seekable) : */
192     int                     i_area_nb;
193     input_area_t **         pp_areas;    /* list of areas in stream == offset
194                                           * interval with own properties */
195     input_area_t *          p_selected_area;
196     input_area_t *          p_new_area;  /* Newly selected area from
197                                           * the interface */
198
199     u32                     i_mux_rate; /* the rate we read the stream (in
200                                          * units of 50 bytes/s) ; 0 if undef */
201
202     /* New status and rate requested by the interface */
203     int                     i_new_status, i_new_rate;
204     int                     b_new_mute;          /* int because it can be -1 */
205     vlc_cond_t              stream_wait; /* interface -> input in case of a
206                                           * status change request            */
207
208     /* Demultiplexer data */
209     void *                  p_demux_data;
210
211     /* Programs descriptions */
212     int                     i_pgrm_number;    /* size of the following array */
213     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
214
215     /* ES descriptions */
216     int                     i_es_number;
217     es_descriptor_t **      pp_es;             /* carried elementary streams */
218     int                     i_selected_es_number;
219     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
220     es_descriptor_t *       p_newly_selected_es;   /* ES selected from
221                                                     * the interface */
222     es_descriptor_t *       p_removed_es;   /* ES removed from the interface */
223
224
225     /* Stream control */
226     stream_ctrl_t           control;
227
228     /* Statistics */
229     count_t                 c_packets_read;                  /* packets read */
230     count_t                 c_packets_trashed;            /* trashed packets */
231 } stream_descriptor_t;
232
233 #define MUTE_NO_CHANGE      -1
234
235 /*****************************************************************************
236  * input_thread_t
237  *****************************************************************************
238  * This structure includes all the local static variables of an input thread
239  *****************************************************************************/
240 struct vout_thread_s;
241 struct bit_stream_s;
242
243 typedef struct input_thread_s
244 {
245     /* Thread properties and locks */
246     boolean_t               b_die;                             /* 'die' flag */
247     boolean_t               b_error;
248     boolean_t               b_eof;
249     vlc_thread_t            thread_id;            /* id for thread functions */
250     int *                   pi_status;              /* temporary status flag */
251
252     /* Input module */
253     struct module_s *       p_input_module;
254
255     /* Init/End */
256     void                 (* pf_init)( struct input_thread_s * );
257     void                 (* pf_open)( struct input_thread_s * );
258     void                 (* pf_close)( struct input_thread_s * );
259     void                 (* pf_end)( struct input_thread_s * );
260     void                 (* pf_init_bit_stream)( struct bit_stream_s *,
261                               struct decoder_fifo_s *,
262                 void (* pf_bitstream_callback)( struct bit_stream_s *,
263                                                 boolean_t ),
264                               void * );
265
266     /* Read & Demultiplex */
267     int                  (* pf_read)( struct input_thread_s *,
268                                       struct data_packet_s * pp_packets[] );
269     void                 (* pf_demux)( struct input_thread_s *,
270                                        struct data_packet_s * );
271
272     /* Packet management facilities */
273     struct data_packet_s *(*pf_new_packet)( void *, size_t );
274     struct pes_packet_s *(* pf_new_pes)( void * );
275     void                 (* pf_delete_packet)( void *,
276                                                struct data_packet_s * );
277     void                 (* pf_delete_pes)( void *, struct pes_packet_s * );
278
279     /* Stream control capabilities */
280     int                  (* pf_set_area)( struct input_thread_s *,
281                                           struct input_area_s * );
282     int                  (* pf_rewind)( struct input_thread_s * );
283                                            /* NULL if we don't support going *
284                                             * backwards (it's gonna be fun)  */
285     void                 (* pf_seek)( struct input_thread_s *, off_t );
286
287     char *                  p_source;
288
289     int                     i_handle;           /* socket or file descriptor */
290     FILE *                  p_stream;                       /* if applicable */
291     int                     i_read_once;        /* number of packet read by
292                                                  * pf_read once */
293     void *                  p_method_data;     /* data of the packet manager */
294     void *                  p_plugin_data;             /* data of the plugin */
295
296     /* General stream description */
297     stream_descriptor_t     stream;                            /* PAT tables */
298
299     count_t                 c_loops;
300 } input_thread_t;
301
302 /* Input methods */
303 /* The first figure is a general method that can be used in interface plugins ;
304  * The second figure is a detailed sub-method */
305 #define INPUT_METHOD_NONE         0x0            /* input thread is inactive */
306 #define INPUT_METHOD_FILE        0x10   /* stream is read from file p_source */
307 #define INPUT_METHOD_DISC        0x20   /* stream is read directly from disc */
308 #define INPUT_METHOD_DVD         0x21             /* stream is read from DVD */
309 #define INPUT_METHOD_VCD         0x22             /* stream is read from VCD */
310 #define INPUT_METHOD_NETWORK     0x30         /* stream is read from network */
311 #define INPUT_METHOD_UCAST       0x31                         /* UDP unicast */
312 #define INPUT_METHOD_MCAST       0x32                       /* UDP multicast */
313 #define INPUT_METHOD_BCAST       0x33                       /* UDP broadcast */
314 #define INPUT_METHOD_VLAN_BCAST  0x34            /* UDP broadcast with VLANs */
315
316
317 /* Status changing methods */
318 #define INPUT_STATUS_END            0
319 #define INPUT_STATUS_PLAY           1
320 #define INPUT_STATUS_PAUSE          2
321 #define INPUT_STATUS_FASTER         3
322 #define INPUT_STATUS_SLOWER         4
323
324 /*****************************************************************************
325  * Prototypes
326  *****************************************************************************/
327 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
328                                              int *pi_status );
329 void input_DestroyThread( struct input_thread_s *, int *pi_status );
330
331 void input_SetStatus( struct input_thread_s *, int );
332 void input_Seek     ( struct input_thread_s *, off_t );
333 void input_DumpStream( struct input_thread_s * );
334 char * input_OffsetToTime( struct input_thread_s *, char * psz_buffer, off_t );
335 int  input_ChangeES ( struct input_thread_s *, struct es_descriptor_s *, u8 );
336 int  input_ToggleES ( struct input_thread_s *,
337                       struct es_descriptor_s *,
338                       boolean_t );
339 int  input_ChangeArea( struct input_thread_s *, struct input_area_s * );
340 int  input_ToggleGrayscale( struct input_thread_s * );
341 int  input_ToggleMute( struct input_thread_s * );
342 int  input_SetSMP( struct input_thread_s *, int );
343