]> git.sesse.net Git - vlc/blob - include/input_ext-intf.h
* Pause function implemented ('p' key).
[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.16 2001/02/08 13:08:02 massiot Exp $
8  *
9  * Authors:
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 /*****************************************************************************
37  * es_descriptor_t: elementary stream descriptor
38  *****************************************************************************
39  * Describes an elementary stream, and includes fields required to handle and
40  * demultiplex this elementary stream.
41  *****************************************************************************/
42 struct decoder_fifo_s;                         /* defined in input_ext-dec.h */
43 struct pgrm_descriptor_s;
44
45 typedef struct es_descriptor_s
46 {
47     u16                     i_id;            /* stream ID for PS, PID for TS */
48     u8                      i_stream_id;     /* stream ID defined in the PES */
49     u8                      i_type;                           /* stream type */
50     boolean_t               b_audio;      /* is the stream an audio stream that
51                                            * will need to be discarded with
52                                            * fast forward and slow motion ?  */
53
54     /* Demultiplexer information */
55     void *                  p_demux_data;
56     struct pgrm_descriptor_s *
57                             p_pgrm;  /* very convenient in the demultiplexer */
58
59     /* PES parser information */
60     struct pes_packet_s *   p_pes;                            /* Current PES */
61     struct data_packet_s *  p_last;   /* The last packet gathered at present */
62     int                     i_pes_real_size;   /* as indicated by the header */
63     boolean_t               b_discontinuity;               /* Stream changed */
64
65     /* Decoder information */
66     struct decoder_fifo_s * p_decoder_fifo;
67     vlc_thread_t            thread_id;                  /* ID of the decoder */
68
69 #ifdef STATS
70     count_t                 c_payload_bytes;/* total of payload useful bytes */
71     count_t                 c_packets;                 /* total packets read */
72     count_t                 c_invalid_packets;       /* invalid packets read */
73 #endif
74 } es_descriptor_t;
75
76 /* Special PID values - note that the PID is only on 13 bits, and that values
77  * greater than 0x1fff have no meaning in a stream */
78 #define PROGRAM_ASSOCIATION_TABLE_PID   0x0000
79 #define CONDITIONNAL_ACCESS_TABLE_PID   0x0001                   /* not used */
80 #define EMPTY_ID                        0xffff    /* empty record in a table */
81  
82 /* ES streams types - see ISO/IEC 13818-1 table 2-29 numbers */
83 #define MPEG1_VIDEO_ES      0x01
84 #define MPEG2_VIDEO_ES      0x02
85 #define MPEG1_AUDIO_ES      0x03
86 #define MPEG2_AUDIO_ES      0x04
87 #define AC3_AUDIO_ES        0x81
88 /* These ones might violate the norm : */
89 #define DVD_SPU_ES          0x82
90 #define LPCM_AUDIO_ES       0x83
91 #define UNKNOWN_ES          0xFF
92
93 /*****************************************************************************
94  * pgrm_descriptor_t
95  *****************************************************************************
96  * Describes a program and list associated elementary streams. It is build by
97  * the PSI decoder upon the informations carried in program map sections
98  *****************************************************************************/
99 typedef struct pgrm_descriptor_s
100 {
101     /* Program characteristics */
102     u16                     i_number;                      /* program number */
103     u8                      i_version;                     /* version number */
104     boolean_t               b_is_ok;      /* Is the description up to date ? */
105
106     /* Service Descriptor (program name) - DVB extension */
107     u8                      i_srv_type;
108     char *                  psz_srv_name;
109
110     /* Synchronization information */
111     mtime_t                 delta_cr;
112     mtime_t                 cr_ref, sysdate_ref;
113     mtime_t                 last_cr; /* reference to detect unexpected stream
114                                       * discontinuities                      */
115     count_t                 c_average_count;
116                            /* counter used to compute dynamic average values */
117     int                     i_synchro_state;
118     boolean_t               b_discontinuity;
119
120     /* Demultiplexer data */
121     void *                  p_demux_data;
122
123     /* Decoders control */
124     struct vout_thread_s *  p_vout;
125     struct aout_thread_s *  p_aout;
126
127     int                     i_es_number;      /* size of the following array */
128     es_descriptor_t **      pp_es;                /* array of pointers to ES */
129 } pgrm_descriptor_t;
130
131 /* Synchro states */
132 #define SYNCHRO_OK          0
133 #define SYNCHRO_START       1
134 #define SYNCHRO_REINIT      2
135
136 /*****************************************************************************
137  * stream_descriptor_t
138  *****************************************************************************
139  * Describes a stream and list its associated programs. Build upon
140  * the information carried in program association sections (for instance)
141  *****************************************************************************/
142 typedef struct stream_descriptor_s
143 {
144     u16                     i_stream_id;                        /* stream id */
145     vlc_mutex_t             stream_lock;  /* to be taken every time you read
146                                            * or modify stream, pgrm or es    */
147
148     /* Input method data */
149     boolean_t               b_pace_control;    /* can we read when we want ? */
150     boolean_t               b_seekable;               /* can we do lseek() ? */
151     /* if (b_seekable) : */
152     off_t                   i_size;                  /* total size of the file
153                                                       * (in arbitrary units) */
154     off_t                   i_tell;             /* actual location in the file
155                                                  * (in arbitrary units) */
156     off_t                   i_seek;         /* next requested location (changed
157                                              * by the interface thread */
158
159     /* New status and rate requested by the interface */
160     int                     i_new_status, i_new_rate;
161     vlc_cond_t              stream_wait; /* interface -> input in case of a
162                                           * status change request            */
163
164     /* Demultiplexer data */
165     void *                  p_demux_data;
166
167     /* Programs descriptions */
168     int                     i_pgrm_number;    /* size of the following array */
169     pgrm_descriptor_t **    pp_programs;        /* array of pointers to pgrm */
170
171     /* ES descriptions */
172     int                     i_es_number;
173     es_descriptor_t **      pp_es;             /* carried elementary streams */
174     int                     i_selected_es_number;
175     es_descriptor_t **      pp_selected_es;             /* ES with a decoder */
176
177     /* Stream control */
178     stream_ctrl_t           control;
179 } stream_descriptor_t;
180
181 /*****************************************************************************
182  * i_p_config_t
183  *****************************************************************************
184  * This structure gives plugins pointers to the useful functions of input
185  *****************************************************************************/
186 struct input_thread_s;
187 struct data_packet_s;
188 struct es_descriptor_s;
189
190 typedef struct i_p_config_s
191 {
192     int                 (* pf_peek_stream)( struct input_thread_s *,
193                                             byte_t * buffer, size_t );
194     void                (* pf_demux_pes)( struct input_thread_s *,
195                                           struct data_packet_s *,
196                                           struct es_descriptor_s *,
197                                           boolean_t b_unit_start,
198                                           boolean_t b_packet_lost );
199 } i_p_config_t;
200
201 /*****************************************************************************
202  * input_thread_t
203  *****************************************************************************
204  * This structure includes all the local static variables of an input thread
205  *****************************************************************************/
206 struct aout_thread_s;
207 struct vout_thread_s;
208
209 typedef struct input_thread_s
210 {
211     /* Thread properties and locks */
212     boolean_t               b_die;                             /* 'die' flag */
213     boolean_t               b_error;
214     boolean_t               b_eof;
215     vlc_thread_t            thread_id;            /* id for thread functions */
216     int *                   pi_status;              /* temporary status flag */
217
218     /* Input module */
219     struct module_s *       p_input_module;
220
221     /* Init/End */
222     void                 (* pf_init)( struct input_thread_s * );
223     void                 (* pf_open)( struct input_thread_s * );
224     void                 (* pf_close)( struct input_thread_s * );
225     void                 (* pf_end)( struct input_thread_s * );
226
227     /* Read & Demultiplex */
228     int                  (* pf_read)( struct input_thread_s *,
229                                       struct data_packet_s * pp_packets[] );
230     void                 (* pf_demux)( struct input_thread_s *,
231                                        struct data_packet_s * );
232
233     /* Packet management facilities */
234     struct data_packet_s *(*pf_new_packet)( void *, size_t );
235     struct pes_packet_s *(* pf_new_pes)( void * );
236     void                 (* pf_delete_packet)( void *,
237                                                struct data_packet_s * );
238     void                 (* pf_delete_pes)( void *, struct pes_packet_s * );
239
240     /* Stream control capabilities */
241     int                  (* pf_rewind)( struct input_thread_s * );
242                                            /* NULL if we don't support going *
243                                             * backwards (it's gonna be fun)  */
244     int                  (* pf_seek)( struct input_thread_s *, off_t );
245
246     i_p_config_t            i_p_config;              /* plugin configuration */
247     char *                  p_source;
248
249     int                     i_handle;           /* socket or file descriptor */
250     void *                  p_method_data;     /* data of the packet manager */
251     void *                  p_plugin_data;             /* data of the plugin */
252
253     /* General stream description */
254     stream_descriptor_t     stream;                            /* PAT tables */
255
256     /* For auto-launch of decoders */
257     struct aout_thread_s *  p_default_aout;
258     struct vout_thread_s *  p_default_vout;
259
260 #ifdef STATS
261     count_t                 c_loops;
262     count_t                 c_bytes;                           /* bytes read */
263     count_t                 c_payload_bytes;         /* payload useful bytes */
264     count_t                 c_packets_read;                  /* packets read */
265     count_t                 c_packets_trashed;            /* trashed packets */
266 #endif
267 } input_thread_t;
268
269
270 /*
271  * Communication interface -> input
272  */
273
274 /*****************************************************************************
275  * input_config_t
276  *****************************************************************************
277  * This structure is given by the interface to an input thread
278  *****************************************************************************/
279 typedef struct input_config_s
280 {
281     /* Input method description */
282     int                         i_method;                    /* input method */
283     char *                      p_source;                          /* source */
284
285     /* For auto-launch of decoders */
286     struct aout_thread_s *      p_default_aout;
287     struct vout_thread_s *      p_default_vout;
288 } input_config_t;
289
290 /* Input methods */
291 #define INPUT_METHOD_NONE           0            /* input thread is inactive */
292 #define INPUT_METHOD_FILE          10   /* stream is read from file p_source */
293 #define INPUT_METHOD_DVD           11      /* stream is read from dvd device */
294 #define INPUT_METHOD_UCAST         20                         /* UDP unicast */
295 #define INPUT_METHOD_MCAST         21                       /* UDP multicast */
296 #define INPUT_METHOD_BCAST         22                       /* UDP broadcast */
297 #define INPUT_METHOD_VLAN_BCAST    32            /* UDP broadcast with VLANs */
298
299 /*****************************************************************************
300  * Prototypes
301  *****************************************************************************/
302 struct input_thread_s * input_CreateThread ( struct playlist_item_s *,
303                                              int *pi_status );
304 void input_DestroyThread( struct input_thread_s *, int *pi_status );
305 void input_Play   ( struct input_thread_s * );
306 void input_Pause  ( struct input_thread_s * );
307 void input_Forward( struct input_thread_s *, int );