]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
- added a NULL pointer test
[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.84 2003/01/16 23:25:54 lool 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 #ifndef _VLC_INPUT_EXT_INTF_H
27 #define _VLC_INPUT_EXT_INTF_H 1
28
29 /*
30  * Communication input -> interface
31  */
32 /* FIXME ! */
33 #define REQUESTED_MPEG         1
34 #define REQUESTED_A52          2
35 #define REQUESTED_LPCM         3
36 #define REQUESTED_NOAUDIO    255
37
38 #define OFFSETTOTIME_MAX_SIZE       10
39
40 /*****************************************************************************
41  * es_descriptor_t: elementary stream descriptor
42  *****************************************************************************
43  * Describes an elementary stream, and includes fields required to handle and
44  * demultiplex this elementary stream.
45  *****************************************************************************/
46 struct es_descriptor_t
47 {
48     uint16_t                i_id;            /* stream ID for PS, PID for TS */
49     uint8_t                 i_stream_id;     /* stream ID defined in the PES */
50     vlc_fourcc_t            i_fourcc;                         /* stream type */
51     uint8_t                 i_cat;    /* stream category (audio, video, spu) */
52     int                     i_demux_fd;   /* used to store demux device
53                                              file handle */
54     char                    psz_desc[20]; /* description of ES: audio language
55                                            * for instance ; NULL if not
56                                            *  available */
57
58     /* Demultiplexer information */
59     es_sys_t *              p_demux_data;
60     pgrm_descriptor_t *     p_pgrm;  /* very convenient in the demultiplexer */
61
62     /* PES parser information */
63     pes_packet_t *          p_pes;                            /* Current PES */
64     unsigned int            i_pes_real_size;   /* as indicated by the header */
65
66     /* Decoder information */
67     decoder_fifo_t *        p_decoder_fifo;
68     void *                  p_waveformatex;
69     void *                  p_bitmapinfoheader;
70
71     count_t                 c_packets;                 /* total packets read */
72     count_t                 c_invalid_packets;       /* invalid packets read */
73 };
74
75 /* Special PID values - note that the PID is only on 13 bits, and that values
76  * greater than 0x1fff have no meaning in a stream */
77 #define PROGRAM_ASSOCIATION_TABLE_PID   0x0000
78 #define CONDITIONNAL_ACCESS_TABLE_PID   0x0001                   /* not used */
79 #define EMPTY_ID                        0xffff    /* empty record in a table */
80
81
82 /* ES Categories to be used by interface plugins */
83 #define UNKNOWN_ES      0x00
84 #define VIDEO_ES        0x01
85 #define AUDIO_ES        0x02
86 #define SPU_ES          0x03
87 #define NAV_ES          0x04
88
89 /*****************************************************************************
90  * pgrm_descriptor_t
91  *****************************************************************************
92  * Describes a program and list associated elementary streams. It is build by
93  * the PSI decoder upon the informations carried in program map sections
94  *****************************************************************************/
95 struct pgrm_descriptor_t
96 {
97     /* Program characteristics */
98     uint16_t                i_number;                      /* program number */
99     uint8_t                 i_version;                     /* version number */
100     vlc_bool_t              b_is_ok;      /* Is the description up to date ? */
101
102     /* Service Descriptor (program name) - DVB extension */
103     uint8_t                 i_srv_type;
104     char *                  psz_srv_name;
105
106     /* Synchronization information */
107     mtime_t                 delta_cr;
108     mtime_t                 cr_ref, sysdate_ref;
109     mtime_t                 last_cr; /* reference to detect unexpected stream
110                                       * discontinuities                      */
111     mtime_t                 last_syscr;
112     count_t                 c_average_count;
113                            /* counter used to compute dynamic average values */
114     int                     i_synchro_state;
115
116     /* Demultiplexer data */
117     pgrm_sys_t *            p_demux_data;
118
119     unsigned int            i_es_number;      /* size of the following array */
120     es_descriptor_t **      pp_es;                /* array of pointers to ES */
121 };
122
123 /* Synchro states */
124 #define SYNCHRO_OK          0
125 #define SYNCHRO_START       1
126 #define SYNCHRO_REINIT      2
127
128 /*****************************************************************************
129  * input_area_t
130  *****************************************************************************
131  * Attributes for current area (title for DVD)
132  *****************************************************************************/
133 struct input_area_t
134 {
135     /* selected area attributes */
136     unsigned int            i_id;        /* identificator for area */
137     off_t                   i_start;     /* start offset of area */
138     off_t                   i_size;      /* total size of the area
139                                           * (in arbitrary units) */
140
141     /* navigation parameters */
142     off_t                   i_tell;      /* actual location in the area
143                                           * (in arbitrary units) */
144     off_t                   i_seek;      /* next requested location
145                                           * (changed by the interface thread */
146
147     /* area subdivision */
148     unsigned int            i_part_nb;   /* number of parts (chapter for DVD)*/
149     unsigned int            i_part;      /* currently selected part */
150
151
152     /* offset to plugin related data */
153     off_t                   i_plugin_data;
154 };
155
156 /**
157  * \brief A list of info items.
158  *
159  * Composes a linked list of name/value pairs intended to inform the
160  * user about the current stream
161  * \see input_AddInfo
162  */
163 struct input_info_t {
164     /**
165      * Name of this item
166      */
167     char *         psz_name;
168
169     /**
170      * Value of this item
171      */
172     char *         psz_value;
173
174     /**
175      * Pointer to next item in list, or NULL it at end of list
176      */
177     input_info_t * p_next;
178 };
179
180 /**
181  * \brief A list of info categories.
182  *
183  * Composes a NULL terminated linked list of categories in which to
184  * place info about the stream.
185  *
186  * \see input_InfoCategory
187  */
188 struct input_info_category_t {
189     /**
190      * The name of this category
191      */
192     char *                  psz_name;
193
194     /**
195      * first element of a linked list containing info items
196      */
197     input_info_t *          p_info;
198
199     /**
200      * Pointer to next element in this list, or NULL if at end of list
201      */
202     input_info_category_t * p_next;
203 };
204
205 /*****************************************************************************
206 * stream_descriptor_t
207  *****************************************************************************
208  * Describes a stream and list its associated programs. Build upon
209  * the information carried in program association sections (for instance)
210  *****************************************************************************/
211 struct stream_descriptor_t
212 {
213     uint16_t                i_stream_id;                        /* stream id */
214     vlc_bool_t              b_changed;    /* if stream has been changed,
215                                              we have to inform the interface */
216     vlc_mutex_t             stream_lock;  /* to be taken every time you read
217                                            * or modify stream, pgrm or es    */
218
219     /* Input method data */
220     unsigned int            i_method;       /* input method for stream: file,
221                                                disc or network */
222     vlc_bool_t              b_pace_control;    /* can we read when we want ? */
223     vlc_bool_t              b_seekable;               /* can we do lseek() ? */
224     vlc_bool_t              b_connected;     /* does read() == 0 imply EOF ? */
225
226     /* if (b_seekable) : */
227     unsigned int            i_area_nb;
228     input_area_t **         pp_areas;    /* list of areas in stream == offset
229                                           * interval with own properties */
230     input_area_t *          p_selected_area;
231     input_area_t *          p_new_area;  /* Newly selected area from
232                                           * the interface */
233
234     uint32_t                i_mux_rate; /* the rate we read the stream (in
235                                          * units of 50 bytes/s) ; 0 if undef */
236
237     /* New status and rate requested by the interface */
238     unsigned int            i_new_status, i_new_rate;
239     int                     b_new_mute;          /* int because it can be -1 */
240     vlc_cond_t              stream_wait; /* interface -> input in case of a
241                                           * status change request            */
242
243     /* Demultiplexer data */
244     stream_sys_t *          p_demux_data;
245
246     /* Programs descriptions */
247     unsigned int            i_pgrm_number;    /* size of the following array */
248     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
249     pgrm_descriptor_t *     p_selected_program;   /* currently
250                                                  selected program */
251     pgrm_descriptor_t *     p_new_program;        /* Newly selected program */
252     /* ES descriptions */
253     unsigned int            i_es_number;
254     es_descriptor_t **      pp_es;             /* carried elementary streams */
255     unsigned int            i_selected_es_number;
256     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
257     es_descriptor_t *       p_newly_selected_es;   /* ES selected from
258                                                     * the interface */
259     es_descriptor_t *       p_removed_es;   /* ES removed from the interface */
260
261     /* Stream control */
262     stream_ctrl_t           control;
263
264     /* Optional stream output */
265     sout_instance_t *       p_sout;
266
267     /* Input info */
268     input_info_category_t * p_info;
269
270     /* Statistics */
271     count_t                 c_packets_read;                  /* packets read */
272     count_t                 c_packets_trashed;            /* trashed packets */
273 };
274
275 /*****************************************************************************
276  * stream_position_t
277  *****************************************************************************
278  * Describes the current position in the stream.
279  *****************************************************************************/
280 struct stream_position_t
281 {
282     off_t    i_tell;     /* actual location in the area (in arbitrary units) */
283     off_t    i_size;          /* total size of the area (in arbitrary units) */
284
285     uint32_t i_mux_rate;                /* the rate we read the stream (in
286                                          * units of 50 bytes/s) ; 0 if undef */
287 };
288
289 #define MUTE_NO_CHANGE      -1
290
291 /*****************************************************************************
292  * input_thread_t
293  *****************************************************************************
294  * This structure includes all the local static variables of an input thread
295  *****************************************************************************/
296 struct input_thread_t
297 {
298     VLC_COMMON_MEMBERS
299
300     /* Thread properties */
301     vlc_bool_t              b_eof;
302
303     /* Access module */
304     module_t *       p_access;
305     ssize_t       (* pf_read ) ( input_thread_t *, byte_t *, size_t );
306     int           (* pf_set_program )( input_thread_t *, pgrm_descriptor_t * );
307     int           (* pf_set_area )( input_thread_t *, input_area_t * );
308     void          (* pf_seek ) ( input_thread_t *, off_t );
309     access_sys_t *   p_access_data;
310     size_t           i_mtu;
311     int              i_pts_delay;                        /* internal caching */
312
313     /* Demux module */
314     module_t *       p_demux;
315     int           (* pf_demux )  ( input_thread_t * );
316     int           (* pf_rewind ) ( input_thread_t * );
317                                            /* NULL if we don't support going *
318                                             * backwards (it's gonna be fun)  */
319     demux_sys_t *    p_demux_data;                      /* data of the demux */
320
321     /* Buffer manager */
322     input_buffers_t *p_method_data;     /* data of the packet manager */
323     data_buffer_t *  p_data_buffer;
324     byte_t *         p_current_data;
325     byte_t *         p_last_data;
326     size_t           i_bufsize;
327
328     /* General stream description */
329     stream_descriptor_t     stream;
330
331     /* Playlist item */
332     char *  psz_source;
333     char *  psz_access;
334     char *  psz_demux;
335     char *  psz_name;
336
337     count_t c_loops;
338 };
339
340 /* Input methods */
341 /* The first figure is a general method that can be used in interface plugins ;
342  * The second figure is a detailed sub-method */
343 #define INPUT_METHOD_NONE         0x0            /* input thread is inactive */
344 #define INPUT_METHOD_FILE        0x10   /* stream is read from file p_source */
345 #define INPUT_METHOD_DISC        0x20   /* stream is read directly from disc */
346 #define INPUT_METHOD_DVD         0x21             /* stream is read from DVD */
347 #define INPUT_METHOD_VCD         0x22             /* stream is read from VCD */
348 #define INPUT_METHOD_NETWORK     0x30         /* stream is read from network */
349 #define INPUT_METHOD_UCAST       0x31                         /* UDP unicast */
350 #define INPUT_METHOD_MCAST       0x32                       /* UDP multicast */
351 #define INPUT_METHOD_BCAST       0x33                       /* UDP broadcast */
352 #define INPUT_METHOD_VLAN_BCAST  0x34            /* UDP broadcast with VLANs */
353 #define INPUT_METHOD_SATELLITE   0x40               /* stream is read from a */
354                                                            /* satellite card */
355 #define INPUT_METHOD_SLP         0x50                          /* SLP stream */
356
357 /* Status changing methods */
358 #define INPUT_STATUS_END            0
359 #define INPUT_STATUS_PLAY           1
360 #define INPUT_STATUS_PAUSE          2
361 #define INPUT_STATUS_FASTER         3
362 #define INPUT_STATUS_SLOWER         4
363
364 /* Seek modes */
365 #define INPUT_SEEK_SET       0x00
366 #define INPUT_SEEK_CUR       0x01
367 #define INPUT_SEEK_END       0x02
368 #define INPUT_SEEK_BYTES     0x00
369 #define INPUT_SEEK_SECONDS   0x10
370 #define INPUT_SEEK_PERCENT   0x20
371
372 /*****************************************************************************
373  * Prototypes
374  *****************************************************************************/
375 #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
376 input_thread_t * __input_CreateThread ( vlc_object_t *, playlist_item_t * );
377 void   input_StopThread     ( input_thread_t * );
378 void   input_DestroyThread  ( input_thread_t * );
379
380 #define input_SetStatus(a,b) __input_SetStatus(VLC_OBJECT(a),b)
381 VLC_EXPORT( void, __input_SetStatus, ( vlc_object_t *, int ) );
382
383 #define input_Seek(a,b,c) __input_Seek(VLC_OBJECT(a),b,c)
384 VLC_EXPORT( void, __input_Seek, ( vlc_object_t *, off_t, int ) );
385
386 #define input_Tell(a,b) __input_Tell(VLC_OBJECT(a),b)
387 VLC_EXPORT( void, __input_Tell, ( vlc_object_t *, stream_position_t * ) );
388
389 VLC_EXPORT( void, input_DumpStream, ( input_thread_t * ) );
390 VLC_EXPORT( char *, input_OffsetToTime, ( input_thread_t *, char *, off_t ) );
391 VLC_EXPORT( int, input_ToggleES, ( input_thread_t *, es_descriptor_t *, vlc_bool_t ) );
392 VLC_EXPORT( int, input_ChangeArea, ( input_thread_t *, input_area_t * ) );
393 VLC_EXPORT( int, input_ChangeProgram, ( input_thread_t *, uint16_t ) );
394
395 int    input_ToggleGrayscale( input_thread_t * );
396 int    input_ToggleMute     ( input_thread_t * );
397
398 #endif /* "input_ext-intf.h" */