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