]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
Some heavy changes today:
[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.55 2001/12/30 07:09:54 sam 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 /* FIXME ! */
30 #define REQUESTED_MPEG         1
31 #define REQUESTED_AC3          2
32 #define REQUESTED_LPCM         3
33 #define REQUESTED_NOAUDIO    255
34
35 #define OFFSETTOTIME_MAX_SIZE       10
36
37 /*****************************************************************************
38  * es_descriptor_t: elementary stream descriptor
39  *****************************************************************************
40  * Describes an elementary stream, and includes fields required to handle and
41  * demultiplex this elementary stream.
42  *****************************************************************************/
43 struct decoder_fifo_s;                         /* defined in input_ext-dec.h */
44 struct pgrm_descriptor_s;
45
46 typedef struct es_descriptor_s
47 {
48     u16                     i_id;            /* stream ID for PS, PID for TS */
49     u8                      i_stream_id;     /* stream ID defined in the PES */
50     u8                      i_type;                           /* stream type */
51     boolean_t               b_audio;      /* is the stream an audio stream that
52                                            * will need to be discarded with
53                                            * fast forward and slow motion ?  */
54     u8                      i_cat;        /* stream category: video, audio,
55                                            * spu, other */
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     int                     i_pes_real_size;   /* as indicated by the header */
69
70     /* Decoder information */
71     struct decoder_fifo_s * p_decoder_fifo;
72     vlc_thread_t            thread_id;                  /* ID of the decoder */
73
74     count_t                 c_packets;                 /* total packets read */
75     count_t                 c_invalid_packets;       /* invalid packets read */
76
77     /* Module properties */
78     struct module_s *         p_module;
79     struct decoder_config_s * p_config;
80
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
90 /* ES Categories to be used by interface plugins */
91 #define VIDEO_ES        0x00
92 #define AUDIO_ES        0x01
93 #define SPU_ES          0x02
94 #define NAV_ES          0x03
95 #define UNKNOWN_ES      0xFF
96
97 /*****************************************************************************
98  * pgrm_descriptor_t
99  *****************************************************************************
100  * Describes a program and list associated elementary streams. It is build by
101  * the PSI decoder upon the informations carried in program map sections
102  *****************************************************************************/
103 typedef struct pgrm_descriptor_s
104 {
105     /* Program characteristics */
106     u16                     i_number;                      /* program number */
107     u8                      i_version;                     /* version number */
108     boolean_t               b_is_ok;      /* Is the description up to date ? */
109
110     /* Service Descriptor (program name) - DVB extension */
111     u8                      i_srv_type;
112     char *                  psz_srv_name;
113
114     /* Synchronization information */
115     mtime_t                 delta_cr;
116     mtime_t                 cr_ref, sysdate_ref;
117     mtime_t                 last_cr; /* reference to detect unexpected stream
118                                       * discontinuities                      */
119     mtime_t                 last_syscr;
120     count_t                 c_average_count;
121                            /* counter used to compute dynamic average values */
122     int                     i_synchro_state;
123
124     /* Demultiplexer data */
125     void *                  p_demux_data;
126
127     int                     i_es_number;      /* size of the following array */
128     es_descriptor_t **      pp_es;                /* array of pointers to ES */
129 } pgrm_descriptor_t;
130
131 /* Synchro states */
132 #define SYNCHRO_OK          0
133 #define SYNCHRO_START       1
134 #define SYNCHRO_REINIT      2
135
136 /*****************************************************************************
137  * input_area_t
138  *****************************************************************************
139  * Attributes for current area (title for DVD)
140  *****************************************************************************/
141 typedef struct input_area_s
142 {
143     /* selected area attributes */
144     int                     i_id;        /* identificator for area */
145     off_t                   i_start;     /* start offset of area */
146     off_t                   i_size;      /* total size of the area
147                                           * (in arbitrary units) */
148
149     /* navigation parameters */
150     off_t                   i_tell;      /* actual location in the area
151                                           * (in arbitrary units) */
152     off_t                   i_seek;      /* next requested location
153                                           * (changed by the interface thread */
154
155     /* area subdivision */
156     int                     i_part_nb;   /* number of parts (chapter for DVD)*/
157     int                     i_part;      /* currently selected part */
158
159     int                     i_angle_nb;  /* number of angles/title units */
160     int                     i_angle;
161
162     /* offset to plugin related data */
163     off_t                   i_plugin_data;
164 } input_area_t;
165
166 /*****************************************************************************
167  * stream_descriptor_t
168  *****************************************************************************
169  * Describes a stream and list its associated programs. Build upon
170  * the information carried in program association sections (for instance)
171  *****************************************************************************/
172 typedef struct stream_descriptor_s
173 {
174     u16                     i_stream_id;                        /* stream id */
175     boolean_t               b_changed;    /* if stream has been changed,
176                                              we have to inform the interface */
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     int                     i_method;       /* input method for stream: file,
182                                                disc or network */
183     boolean_t               b_pace_control;    /* can we read when we want ? */
184     boolean_t               b_seekable;               /* can we do lseek() ? */
185
186     /* if (b_seekable) : */
187     int                     i_area_nb;
188     input_area_t **         pp_areas;    /* list of areas in stream == offset
189                                           * interval with own properties */
190     input_area_t *          p_selected_area;
191     input_area_t *          p_new_area;  /* Newly selected area from
192                                           * the interface */
193
194     u32                     i_mux_rate; /* the rate we read the stream (in
195                                          * units of 50 bytes/s) ; 0 if undef */
196
197     /* New status and rate requested by the interface */
198     int                     i_new_status, i_new_rate;
199     int                     b_new_mute;          /* int because it can be -1 */
200     vlc_cond_t              stream_wait; /* interface -> input in case of a
201                                           * status change request            */
202
203     /* Demultiplexer data */
204     void *                  p_demux_data;
205
206     /* Programs descriptions */
207     int                     i_pgrm_number;    /* size of the following array */
208     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
209     pgrm_descriptor_t *     p_selected_program;   /* currently 
210                                                  selected program */
211     pgrm_descriptor_t *     p_new_program;        /* Newly selected program */
212     /* ES descriptions */
213     int                     i_es_number;
214     es_descriptor_t **      pp_es;             /* carried elementary streams */
215     int                     i_selected_es_number;
216     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
217     es_descriptor_t *       p_newly_selected_es;   /* ES selected from
218                                                     * the interface */
219     es_descriptor_t *       p_removed_es;   /* ES removed from the interface */
220
221
222     /* Stream control */
223     stream_ctrl_t           control;
224
225     /* Statistics */
226     count_t                 c_packets_read;                  /* packets read */
227     count_t                 c_packets_trashed;            /* trashed packets */
228 } stream_descriptor_t;
229
230 #define MUTE_NO_CHANGE      -1
231
232 /*****************************************************************************
233  * input_thread_t
234  *****************************************************************************
235  * This structure includes all the local static variables of an input thread
236  *****************************************************************************/
237 struct vout_thread_s;
238 struct bit_stream_s;
239
240 typedef struct input_thread_s
241 {
242     /* Thread properties and locks */
243     boolean_t               b_die;                             /* 'die' flag */
244     boolean_t               b_error;
245     boolean_t               b_eof;
246     vlc_thread_t            thread_id;            /* id for thread functions */
247     int *                   pi_status;              /* temporary status flag */
248
249     /* Input module */
250     struct module_s *       p_input_module;
251
252     /* Init/End */
253     void                 (* pf_init)( struct input_thread_s * );
254     void                 (* pf_open)( struct input_thread_s * );
255     void                 (* pf_close)( struct input_thread_s * );
256     void                 (* pf_end)( struct input_thread_s * );
257     void                 (* pf_init_bit_stream)( struct bit_stream_s *,
258                               struct decoder_fifo_s *,
259                 void (* pf_bitstream_callback)( struct bit_stream_s *,
260                                                 boolean_t ),
261                               void * );
262
263     /* Read & Demultiplex */
264     int                  (* pf_read)( struct input_thread_s *,
265                                       struct data_packet_s ** );
266     void                 (* pf_demux)( struct input_thread_s *,
267                                        struct data_packet_s * );
268
269     /* Packet management facilities */
270     struct data_packet_s *(*pf_new_packet)( void *, size_t );
271     struct pes_packet_s *(* pf_new_pes)( void * );
272     void                 (* pf_delete_packet)( void *,
273                                                struct data_packet_s * );
274     void                 (* pf_delete_pes)( void *, struct pes_packet_s * );
275
276     /* Stream control capabilities */
277     int                  (* pf_set_program)( struct input_thread_s *,
278                                              struct pgrm_descriptor_s * );
279     int                  (* pf_set_area)( struct input_thread_s *,
280                                           struct input_area_s * );
281     int                  (* pf_rewind)( struct input_thread_s * );
282                                            /* NULL if we don't support going *
283                                             * backwards (it's gonna be fun)  */
284     void                 (* pf_seek)( struct input_thread_s *, off_t );
285
286     char *                  p_source;
287
288     int                     i_handle;           /* socket or file descriptor */
289     FILE *                  p_stream;                       /* if applicable */
290     void *                  p_handle;          /* if i_handle isn't suitable */
291     void *                  p_method_data;     /* data of the packet manager */
292     void *                  p_plugin_data;             /* data of the plugin */
293
294     /* General stream description */
295     stream_descriptor_t     stream;                            /* PAT tables */
296
297     count_t                 c_loops;
298 } input_thread_t;
299
300 /* Input methods */
301 /* The first figure is a general method that can be used in interface plugins ;
302  * The second figure is a detailed sub-method */
303 #define INPUT_METHOD_NONE         0x0            /* input thread is inactive */
304 #define INPUT_METHOD_FILE        0x10   /* stream is read from file p_source */
305 #define INPUT_METHOD_DISC        0x20   /* stream is read directly from disc */
306 #define INPUT_METHOD_DVD         0x21             /* stream is read from DVD */
307 #define INPUT_METHOD_VCD         0x22             /* stream is read from VCD */
308 #define INPUT_METHOD_NETWORK     0x30         /* stream is read from network */
309 #define INPUT_METHOD_UCAST       0x31                         /* UDP unicast */
310 #define INPUT_METHOD_MCAST       0x32                       /* UDP multicast */
311 #define INPUT_METHOD_BCAST       0x33                       /* UDP broadcast */
312 #define INPUT_METHOD_VLAN_BCAST  0x34            /* UDP broadcast with VLANs */
313
314
315 /* Status changing methods */
316 #define INPUT_STATUS_END            0
317 #define INPUT_STATUS_PLAY           1
318 #define INPUT_STATUS_PAUSE          2
319 #define INPUT_STATUS_FASTER         3
320 #define INPUT_STATUS_SLOWER         4
321
322 /*****************************************************************************
323  * Prototypes
324  *****************************************************************************/
325 #ifndef PLUGIN
326 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
327                                              int *pi_status );
328 void   input_DestroyThread  ( struct input_thread_s *, int *pi_status );
329
330 void   input_SetStatus      ( struct input_thread_s *, int );
331 void   input_Seek           ( struct input_thread_s *, off_t );
332 void   input_DumpStream     ( struct input_thread_s * );
333 char * input_OffsetToTime   ( struct input_thread_s *, char *, off_t );
334 int    input_ChangeES       ( struct input_thread_s *,
335                               struct es_descriptor_s *, u8 );
336 int    input_ToggleES       ( struct input_thread_s *,
337                               struct es_descriptor_s *, boolean_t );
338 int    input_ChangeArea     ( struct input_thread_s *, struct input_area_s * );
339 int    input_ToggleGrayscale( struct input_thread_s * );
340 int    input_ToggleMute     ( struct input_thread_s * );
341 int    input_SetSMP         ( struct input_thread_s *, int );
342 #else
343 #   define input_SetStatus      p_symbols->input_SetStatus
344 #   define input_Seek           p_symbols->input_Seek
345 #   define input_DumpStream     p_symbols->input_DumpStream
346 #   define input_OffsetToTime   p_symbols->input_OffsetToTime
347 #   define input_ChangeES       p_symbols->input_ChangeES
348 #   define input_ToggleES       p_symbols->input_ToggleES
349 #   define input_ChangeArea     p_symbols->input_ChangeArea
350 #endif
351