]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
* Added functions and hooks to display dates instead of off_t.
[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.26 2001/02/22 17:00:20 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     char                    psz_desc[20]; /* description of ES: audio language
56                                            * for instance ; NULL if not
57                                            *  available */
58
59     /* Demultiplexer information */
60     void *                  p_demux_data;
61     struct pgrm_descriptor_s *
62                             p_pgrm;  /* very convenient in the demultiplexer */
63
64     /* PES parser information */
65     struct pes_packet_s *   p_pes;                            /* Current PES */
66     struct data_packet_s *  p_last;   /* The last packet gathered at present */
67     int                     i_pes_real_size;   /* as indicated by the header */
68
69     /* Decoder information */
70     struct decoder_fifo_s * p_decoder_fifo;
71     vlc_thread_t            thread_id;                  /* ID of the decoder */
72
73 #ifdef STATS
74     count_t                 c_payload_bytes;/* total of payload useful bytes */
75     count_t                 c_packets;                 /* total packets read */
76     count_t                 c_invalid_packets;       /* invalid packets read */
77 #endif
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 /*****************************************************************************
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     count_t                 c_average_count;
120                            /* counter used to compute dynamic average values */
121     int                     i_synchro_state;
122
123     /* Demultiplexer data */
124     void *                  p_demux_data;
125
126     /* Decoders control */
127     struct vout_thread_s *  p_vout;
128     struct aout_thread_s *  p_aout;
129
130     int                     i_es_number;      /* size of the following array */
131     es_descriptor_t **      pp_es;                /* array of pointers to ES */
132 } pgrm_descriptor_t;
133
134 /* Synchro states */
135 #define SYNCHRO_OK          0
136 #define SYNCHRO_START       1
137 #define SYNCHRO_REINIT      2
138
139 /*****************************************************************************
140  * input_area_t
141  *****************************************************************************
142  * Attributes for current area (title for DVD)
143  *****************************************************************************/
144 typedef struct input_area_s
145 {
146     /* selected area attributes */
147     int                     i_id;        /* identificator for area */
148     off_t                   i_start;     /* start offset of area */
149     off_t                   i_size;      /* total size of the area
150                                           * (in arbitrary units) */
151
152     /* navigation parameters */
153     off_t                   i_tell;      /* actual location in the area
154                                           * (in arbitrary units) */
155     off_t                   i_seek;      /* next requested location
156                                           * (changed by the interface thread */
157
158     /* area subdivision */
159     int                     i_part_nb;   /* number of parts (chapter for DVD)*/
160     int                     i_part;      /* currently selected part */
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     vlc_mutex_t             stream_lock;  /* to be taken every time you read
176                                            * or modify stream, pgrm or es    */
177
178     /* Input method data */
179     boolean_t               b_pace_control;    /* can we read when we want ? */
180     boolean_t               b_seekable;               /* can we do lseek() ? */
181
182     /* if (b_seekable) : */
183     int                     i_area_nb;
184     input_area_t **         pp_areas;      /* list of areas in stream == offset
185                                             * interval with own properties */
186     input_area_t *          p_selected_area;
187     u32                     i_mux_rate; /* the rate we read the stream (in
188                                          * units of 50 bytes/s) ; 0 if undef */
189
190     /* New status and rate requested by the interface */
191     int                     i_new_status, i_new_rate;
192     vlc_cond_t              stream_wait; /* interface -> input in case of a
193                                           * status change request            */
194
195     /* Demultiplexer data */
196     void *                  p_demux_data;
197
198     /* Programs descriptions */
199     int                     i_pgrm_number;    /* size of the following array */
200     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
201
202     /* ES descriptions */
203     int                     i_es_number;
204     es_descriptor_t **      pp_es;             /* carried elementary streams */
205     int                     i_selected_es_number;
206     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
207
208     /* Stream control */
209     stream_ctrl_t           control;
210 } stream_descriptor_t;
211
212 /*****************************************************************************
213  * i_p_config_t
214  *****************************************************************************
215  * This structure gives plugins pointers to the useful functions of input
216  *****************************************************************************/
217 struct input_thread_s;
218 struct data_packet_s;
219 struct es_descriptor_s;
220
221 typedef struct i_p_config_s
222 {
223     int                 (* pf_peek_stream)( struct input_thread_s *,
224                                             byte_t * buffer, size_t );
225     void                (* pf_demux_pes)( struct input_thread_s *,
226                                           struct data_packet_s *,
227                                           struct es_descriptor_s *,
228                                           boolean_t b_unit_start,
229                                           boolean_t b_packet_lost );
230 } i_p_config_t;
231
232 /*****************************************************************************
233  * input_thread_t
234  *****************************************************************************
235  * This structure includes all the local static variables of an input thread
236  *****************************************************************************/
237 struct aout_thread_s;
238 struct vout_thread_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
258     /* Read & Demultiplex */
259     int                  (* pf_read)( struct input_thread_s *,
260                                       struct data_packet_s * pp_packets[] );
261     void                 (* pf_demux)( struct input_thread_s *,
262                                        struct data_packet_s * );
263
264     /* Packet management facilities */
265     struct data_packet_s *(*pf_new_packet)( void *, size_t );
266     struct pes_packet_s *(* pf_new_pes)( void * );
267     void                 (* pf_delete_packet)( void *,
268                                                struct data_packet_s * );
269     void                 (* pf_delete_pes)( void *, struct pes_packet_s * );
270
271     /* Stream control capabilities */
272     int                  (* pf_rewind)( struct input_thread_s * );
273                                            /* NULL if we don't support going *
274                                             * backwards (it's gonna be fun)  */
275     void                 (* pf_seek)( struct input_thread_s *, off_t );
276
277     i_p_config_t            i_p_config;              /* plugin configuration */
278     char *                  p_source;
279
280     int                     i_handle;           /* socket or file descriptor */
281     void *                  p_method_data;     /* data of the packet manager */
282     void *                  p_plugin_data;             /* data of the plugin */
283
284     /* General stream description */
285     stream_descriptor_t     stream;                            /* PAT tables */
286
287     /* For auto-launch of decoders */
288     struct aout_thread_s *  p_default_aout;
289     struct vout_thread_s *  p_default_vout;
290
291 #ifdef STATS
292     count_t                 c_loops;
293     count_t                 c_bytes;                           /* bytes read */
294     count_t                 c_payload_bytes;         /* payload useful bytes */
295     count_t                 c_packets_read;                  /* packets read */
296     count_t                 c_packets_trashed;            /* trashed packets */
297 #endif
298 } input_thread_t;
299
300
301 /*
302  * Communication interface -> input
303  */
304
305 /*****************************************************************************
306  * input_config_t
307  *****************************************************************************
308  * This structure is given by the interface to an input thread
309  *****************************************************************************/
310 typedef struct input_config_s
311 {
312     /* Input method description */
313     int                         i_method;                    /* input method */
314     char *                      p_source;                          /* source */
315
316     /* For auto-launch of decoders */
317     struct aout_thread_s *      p_default_aout;
318     struct vout_thread_s *      p_default_vout;
319 } input_config_t;
320
321 /* Input methods */
322 #define INPUT_METHOD_NONE           0            /* input thread is inactive */
323 #define INPUT_METHOD_FILE          10   /* stream is read from file p_source */
324 #define INPUT_METHOD_DVD           11      /* stream is read from dvd device */
325 #define INPUT_METHOD_UCAST         20                         /* UDP unicast */
326 #define INPUT_METHOD_MCAST         21                       /* UDP multicast */
327 #define INPUT_METHOD_BCAST         22                       /* UDP broadcast */
328 #define INPUT_METHOD_VLAN_BCAST    32            /* UDP broadcast with VLANs */
329
330 /* Status changing methods */
331 #define INPUT_STATUS_END            0
332 #define INPUT_STATUS_PLAY           1
333 #define INPUT_STATUS_PAUSE          2
334 #define INPUT_STATUS_FASTER         3
335 #define INPUT_STATUS_SLOWER         4
336
337 /*****************************************************************************
338  * Prototypes
339  *****************************************************************************/
340 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
341                                              int *pi_status );
342 void input_DestroyThread( struct input_thread_s *, int *pi_status );
343
344 void input_SetStatus( struct input_thread_s *, int );
345 void input_SetRate  ( struct input_thread_s *, int );
346 void input_Seek     ( struct input_thread_s *, off_t );
347 void input_DumpStream( struct input_thread_s * );
348 char * input_OffsetToTime( struct input_thread_s *, char * psz_buffer, off_t );