]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
* ./src/interface/main.c: we no longer segfault if argc == 0.
[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.65 2002/04/24 00:36:24 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  * input_bank_t, p_input_bank (global variable)
39  *****************************************************************************
40  * This global variable is accessed by any function using the input.
41  *****************************************************************************/
42 typedef struct input_bank_s
43 {
44     /* Array to all the input threads */
45     struct input_thread_s *pp_input[ INPUT_MAX_THREADS ];
46
47     int                   i_count;
48     vlc_mutex_t           lock;                               /* Global lock */
49
50 } input_bank_t;
51
52 #ifndef __PLUGIN__
53 extern input_bank_t *p_input_bank;
54 #else
55 #   define p_input_bank (p_symbols->p_input_bank)
56 #endif
57
58 /*****************************************************************************
59  * es_descriptor_t: elementary stream descriptor
60  *****************************************************************************
61  * Describes an elementary stream, and includes fields required to handle and
62  * demultiplex this elementary stream.
63  *****************************************************************************/
64 typedef struct es_descriptor_s
65 {
66     u16                     i_id;            /* stream ID for PS, PID for TS */
67     u8                      i_stream_id;     /* stream ID defined in the PES */
68     u8                      i_type;                           /* stream type */
69     boolean_t               b_audio;      /* is the stream an audio stream that
70                                            * will need to be discarded with
71                                            * fast forward and slow motion ?  */
72     u8                      i_cat;        /* stream category: video, audio,
73                                            * spu, other */
74     int                     i_demux_fd;   /* used to store demux device
75                                              file handle */
76     char                    psz_desc[20]; /* description of ES: audio language
77                                            * for instance ; NULL if not
78                                            *  available */
79
80     /* Demultiplexer information */
81     void *                  p_demux_data;
82     struct pgrm_descriptor_s *
83                             p_pgrm;  /* very convenient in the demultiplexer */
84
85     /* PES parser information */
86     struct pes_packet_s *   p_pes;                            /* Current PES */
87     int                     i_pes_real_size;   /* as indicated by the header */
88
89     /* Decoder information */
90     struct decoder_fifo_s * p_decoder_fifo;
91     vlc_thread_t            thread_id;                  /* ID of the decoder */
92
93     count_t                 c_packets;                 /* total packets read */
94     count_t                 c_invalid_packets;       /* invalid packets read */
95
96     /* Module properties */
97     struct module_s *         p_module;
98     struct decoder_config_s * p_config;
99
100 } es_descriptor_t;
101
102 /* Special PID values - note that the PID is only on 13 bits, and that values
103  * greater than 0x1fff have no meaning in a stream */
104 #define PROGRAM_ASSOCIATION_TABLE_PID   0x0000
105 #define CONDITIONNAL_ACCESS_TABLE_PID   0x0001                   /* not used */
106 #define EMPTY_ID                        0xffff    /* empty record in a table */
107  
108
109 /* ES Categories to be used by interface plugins */
110 #define VIDEO_ES        0x00
111 #define AUDIO_ES        0x01
112 #define SPU_ES          0x02
113 #define NAV_ES          0x03
114 #define UNKNOWN_ES      0xFF
115
116 /*****************************************************************************
117  * pgrm_descriptor_t
118  *****************************************************************************
119  * Describes a program and list associated elementary streams. It is build by
120  * the PSI decoder upon the informations carried in program map sections
121  *****************************************************************************/
122 typedef struct pgrm_descriptor_s
123 {
124     /* Program characteristics */
125     u16                     i_number;                      /* program number */
126     u8                      i_version;                     /* version number */
127     boolean_t               b_is_ok;      /* Is the description up to date ? */
128
129     /* Service Descriptor (program name) - DVB extension */
130     u8                      i_srv_type;
131     char *                  psz_srv_name;
132
133     /* Synchronization information */
134     mtime_t                 delta_cr;
135     mtime_t                 cr_ref, sysdate_ref;
136     mtime_t                 last_cr; /* reference to detect unexpected stream
137                                       * discontinuities                      */
138     mtime_t                 last_syscr;
139     count_t                 c_average_count;
140                            /* counter used to compute dynamic average values */
141     int                     i_synchro_state;
142
143     /* Demultiplexer data */
144     void *                  p_demux_data;
145
146     int                     i_es_number;      /* size of the following array */
147     es_descriptor_t **      pp_es;                /* array of pointers to ES */
148 } pgrm_descriptor_t;
149
150 /* Synchro states */
151 #define SYNCHRO_OK          0
152 #define SYNCHRO_START       1
153 #define SYNCHRO_REINIT      2
154
155 /*****************************************************************************
156  * input_area_t
157  *****************************************************************************
158  * Attributes for current area (title for DVD)
159  *****************************************************************************/
160 typedef struct input_area_s
161 {
162     /* selected area attributes */
163     int                     i_id;        /* identificator for area */
164     off_t                   i_start;     /* start offset of area */
165     off_t                   i_size;      /* total size of the area
166                                           * (in arbitrary units) */
167
168     /* navigation parameters */
169     off_t                   i_tell;      /* actual location in the area
170                                           * (in arbitrary units) */
171     off_t                   i_seek;      /* next requested location
172                                           * (changed by the interface thread */
173
174     /* area subdivision */
175     int                     i_part_nb;   /* number of parts (chapter for DVD)*/
176     int                     i_part;      /* currently selected part */
177
178
179     /* offset to plugin related data */
180     off_t                   i_plugin_data;
181 } input_area_t;
182
183 /*****************************************************************************
184  * stream_descriptor_t
185  *****************************************************************************
186  * Describes a stream and list its associated programs. Build upon
187  * the information carried in program association sections (for instance)
188  *****************************************************************************/
189 typedef struct stream_descriptor_s
190 {
191     u16                     i_stream_id;                        /* stream id */
192     boolean_t               b_changed;    /* if stream has been changed,
193                                              we have to inform the interface */
194     vlc_mutex_t             stream_lock;  /* to be taken every time you read
195                                            * or modify stream, pgrm or es    */
196
197     /* Input method data */
198     int                     i_method;       /* input method for stream: file,
199                                                disc or network */
200     boolean_t               b_pace_control;    /* can we read when we want ? */
201     boolean_t               b_seekable;               /* can we do lseek() ? */
202
203     /* if (b_seekable) : */
204     int                     i_area_nb;
205     input_area_t **         pp_areas;    /* list of areas in stream == offset
206                                           * interval with own properties */
207     input_area_t *          p_selected_area;
208     input_area_t *          p_new_area;  /* Newly selected area from
209                                           * the interface */
210
211     u32                     i_mux_rate; /* the rate we read the stream (in
212                                          * units of 50 bytes/s) ; 0 if undef */
213
214     /* New status and rate requested by the interface */
215     int                     i_new_status, i_new_rate;
216     int                     b_new_mute;          /* int because it can be -1 */
217     vlc_cond_t              stream_wait; /* interface -> input in case of a
218                                           * status change request            */
219
220     /* Demultiplexer data */
221     void *                  p_demux_data;
222
223     /* Programs descriptions */
224     int                     i_pgrm_number;    /* size of the following array */
225     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
226     pgrm_descriptor_t *     p_selected_program;   /* currently 
227                                                  selected program */
228     pgrm_descriptor_t *     p_new_program;        /* Newly selected program */
229     /* ES descriptions */
230     int                     i_es_number;
231     es_descriptor_t **      pp_es;             /* carried elementary streams */
232     int                     i_selected_es_number;
233     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
234     es_descriptor_t *       p_newly_selected_es;   /* ES selected from
235                                                     * the interface */
236     es_descriptor_t *       p_removed_es;   /* ES removed from the interface */
237
238
239     /* Stream control */
240     stream_ctrl_t           control;
241
242     /* Statistics */
243     count_t                 c_packets_read;                  /* packets read */
244     count_t                 c_packets_trashed;            /* trashed packets */
245 } stream_descriptor_t;
246
247 #define MUTE_NO_CHANGE      -1
248
249 /*****************************************************************************
250  * input_thread_t
251  *****************************************************************************
252  * This structure includes all the local static variables of an input thread
253  *****************************************************************************/
254 typedef struct input_thread_s
255 {
256     /* Thread properties and locks */
257     boolean_t               b_die;                             /* 'die' flag */
258     boolean_t               b_error;
259     boolean_t               b_eof;
260     vlc_thread_t            thread_id;            /* id for thread functions */
261     int                     i_status;                         /* status flag */
262
263     /* Access module */
264     struct module_s *       p_access_module;
265     int                  (* pf_open)( struct input_thread_s * );
266     void                 (* pf_close)( struct input_thread_s * );
267     ssize_t              (* pf_read) ( struct input_thread_s *,
268                                        byte_t *, size_t );
269     int                  (* pf_set_program)( struct input_thread_s *,
270                                              struct pgrm_descriptor_s * );
271     int                  (* pf_set_area)( struct input_thread_s *,
272                                           struct input_area_s * );
273     void                 (* pf_seek)( struct input_thread_s *, off_t );
274     void *                  p_access_data;
275     size_t                  i_mtu;
276
277     /* Demux module */
278     struct module_s *       p_demux_module;
279     int                  (* pf_init)( struct input_thread_s * );
280     void                 (* pf_end)( struct input_thread_s * );
281     int                  (* pf_demux)( struct input_thread_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 *                  p_demux_data;               /* data of the demux */
286
287     /* Buffer manager */
288     struct input_buffers_s *p_method_data;     /* data of the packet manager */
289     struct data_buffer_s *  p_data_buffer;
290     byte_t *                p_current_data;
291     byte_t *                p_last_data;
292     size_t                  i_bufsize;
293
294     /* General stream description */
295     stream_descriptor_t     stream;
296
297     /* Playlist item */
298     char *                  psz_source;
299     char *                  psz_access;
300     char *                  psz_demux;
301     char *                  psz_name;
302
303     count_t                 c_loops;
304 } input_thread_t;
305
306 /* Input methods */
307 /* The first figure is a general method that can be used in interface plugins ;
308  * The second figure is a detailed sub-method */
309 #define INPUT_METHOD_NONE         0x0            /* input thread is inactive */
310 #define INPUT_METHOD_FILE        0x10   /* stream is read from file p_source */
311 #define INPUT_METHOD_DISC        0x20   /* stream is read directly from disc */
312 #define INPUT_METHOD_DVD         0x21             /* stream is read from DVD */
313 #define INPUT_METHOD_VCD         0x22             /* stream is read from VCD */
314 #define INPUT_METHOD_NETWORK     0x30         /* stream is read from network */
315 #define INPUT_METHOD_UCAST       0x31                         /* UDP unicast */
316 #define INPUT_METHOD_MCAST       0x32                       /* UDP multicast */
317 #define INPUT_METHOD_BCAST       0x33                       /* UDP broadcast */
318 #define INPUT_METHOD_VLAN_BCAST  0x34            /* UDP broadcast with VLANs */
319 #define INPUT_METHOD_SATELLITE   0x40               /* stream is read from a */
320                                                            /* satellite card */
321
322 /* Status changing methods */
323 #define INPUT_STATUS_END            0
324 #define INPUT_STATUS_PLAY           1
325 #define INPUT_STATUS_PAUSE          2
326 #define INPUT_STATUS_FASTER         3
327 #define INPUT_STATUS_SLOWER         4
328
329 /*****************************************************************************
330  * Prototypes
331  *****************************************************************************/
332 #ifndef __PLUGIN__
333 void   input_InitBank       ( void );
334 void   input_EndBank        ( void );
335
336 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
337                                              int *pi_status );
338 void   input_StopThread     ( struct input_thread_s *, int *pi_status );
339 void   input_DestroyThread  ( struct input_thread_s * );
340
341 void   input_SetStatus      ( struct input_thread_s *, int );
342 void   input_Seek           ( struct input_thread_s *, off_t );
343 void   input_DumpStream     ( struct input_thread_s * );
344 char * input_OffsetToTime   ( struct input_thread_s *, char *, off_t );
345 int    input_ChangeES       ( struct input_thread_s *,
346                               struct es_descriptor_s *, u8 );
347 int    input_ToggleES       ( struct input_thread_s *,
348                               struct es_descriptor_s *, boolean_t );
349 int    input_ChangeArea     ( struct input_thread_s *, struct input_area_s * );
350 int    input_ChangeProgram  ( struct input_thread_s *, u16 );
351 int    input_ToggleGrayscale( struct input_thread_s * );
352 int    input_ToggleMute     ( struct input_thread_s * );
353 int    input_SetSMP         ( struct input_thread_s *, int );
354 #else
355 #   define input_SetStatus      p_symbols->input_SetStatus
356 #   define input_Seek           p_symbols->input_Seek
357 #   define input_DumpStream     p_symbols->input_DumpStream
358 #   define input_OffsetToTime   p_symbols->input_OffsetToTime
359 #   define input_ChangeES       p_symbols->input_ChangeES
360 #   define input_ToggleES       p_symbols->input_ToggleES
361 #   define input_ChangeArea     p_symbols->input_ChangeArea
362 #   define input_ChangeProgram  p_symbols->input_ChangeProgram
363 #endif
364