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