]> git.sesse.net Git - vlc/blob - include/vlc_input.h
* src/misc/vlm.c: started "vod server" integration (not much done yet).
[vlc] / include / vlc_input.h
1 /*****************************************************************************
2  * vlc_input.h:
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: input_ext-intf.h 7954 2004-06-07 22:19:12Z fenrir $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /* __ is need because conflict with <vlc/input.h> */
26 #ifndef _VLC__INPUT_H
27 #define _VLC__INPUT_H 1
28
29 /*****************************************************************************
30  * input_item_t: Describes an input and is used to spawn input_thread_t objects
31  *****************************************************************************/
32 struct info_t
33 {
34     char *psz_name;            /**< Name of this info */
35     char *psz_value;           /**< Value of the info */
36 };
37
38 struct info_category_t
39 {
40     char   *psz_name;      /**< Name of this category */
41     int    i_infos;        /**< Number of infos in the category */
42     struct info_t **pp_infos;     /**< Pointer to an array of infos */
43 };
44
45 struct input_item_t
46 {
47     char       *psz_name;            /**< text describing this item */
48     char       *psz_uri;             /**< mrl of this item */
49
50     int        i_options;            /**< Number of input options */
51     char       **ppsz_options;       /**< Array of input options */
52
53     mtime_t    i_duration;           /**< A hint about the duration of this
54                                       * item, in milliseconds*/
55
56     int        i_categories;         /**< Number of info categories */
57     info_category_t **pp_categories; /**< Pointer to the first info category */
58
59     int         i_es;                /**< Number of es format descriptions */
60     es_format_t **es;                /**< Pointer to an array of es formats */
61
62     vlc_mutex_t lock;                /**< Item cannot be changed without this lock */
63 };
64
65
66 /*****************************************************************************
67  * Seek point: (generalisation of chapters)
68  *****************************************************************************/
69 struct seekpoint_t
70 {
71     int64_t i_byte_offset;
72     int64_t i_time_offset;
73     char    *psz_name;
74 };
75
76 static inline seekpoint_t *vlc_seekpoint_New( void )
77 {
78     seekpoint_t *point = (seekpoint_t*)malloc( sizeof( seekpoint_t ) );
79     point->i_byte_offset =
80     point->i_time_offset = 0;
81     point->psz_name = NULL;
82     return point;
83 }
84
85 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
86 {
87     if( !point ) return;
88     if( point->psz_name ) free( point->psz_name );
89     free( point );
90 }
91
92 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
93 {
94     seekpoint_t *point = vlc_seekpoint_New();
95     if( src->psz_name ) point->psz_name = strdup( src->psz_name );
96     point->i_time_offset = src->i_time_offset;
97     point->i_byte_offset = src->i_byte_offset;
98     return point;
99 }
100
101 /*****************************************************************************
102  * Title:
103  *****************************************************************************/
104 typedef struct
105 {
106     char        *psz_name;
107
108     vlc_bool_t  b_menu;      /* Is it a menu or a normal entry */
109
110     int64_t     i_length;   /* Length(microsecond) if known, else 0 */
111     int64_t     i_size;     /* Size (bytes) if known, else 0 */
112
113     /* Title seekpoint */
114     int         i_seekpoint;
115     seekpoint_t **seekpoint;
116
117 } input_title_t;
118
119 static inline input_title_t *vlc_input_title_New( )
120 {
121     input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
122
123     t->psz_name = NULL;
124     t->b_menu = VLC_FALSE;
125     t->i_length = 0;
126     t->i_size   = 0;
127     t->i_seekpoint = 0;
128     t->seekpoint = NULL;
129
130     return t;
131 }
132 static inline void vlc_input_title_Delete( input_title_t *t )
133 {
134     int i;
135     if( t == NULL )
136         return;
137
138     if( t->psz_name ) free( t->psz_name );
139     for( i = 0; i < t->i_seekpoint; i++ )
140     {
141         if( t->seekpoint[i]->psz_name ) free( t->seekpoint[i]->psz_name );
142         free( t->seekpoint[i] );
143     }
144     if( t->seekpoint ) free( t->seekpoint );
145     free( t );
146 }
147
148 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
149 {
150     input_title_t *dup = vlc_input_title_New( );
151     int i;
152
153     if( t->psz_name ) dup->psz_name = strdup( t->psz_name );
154     dup->b_menu      = t->b_menu;
155     dup->i_length    = t->i_length;
156     dup->i_size      = t->i_size;
157     dup->i_seekpoint = t->i_seekpoint;
158     if( t->i_seekpoint > 0 )
159     {
160         dup->seekpoint = (seekpoint_t**)calloc( t->i_seekpoint,
161                                                 sizeof(seekpoint_t*) );
162
163         for( i = 0; i < t->i_seekpoint; i++ )
164         {
165             dup->seekpoint[i] = vlc_seekpoint_Duplicate( t->seekpoint[i] );
166         }
167     }
168
169     return dup;
170 }
171
172
173 /*****************************************************************************
174  * input defines/constants.
175  *****************************************************************************/
176
177 /* "state" value */
178 enum input_state_e
179 {
180     INIT_S,
181     PLAYING_S,
182     PAUSE_S,
183     END_S,
184 };
185
186 /* "rate" default, min/max */
187 #define INPUT_RATE_DEFAULT  1000
188 #define INPUT_RATE_MIN       125            /* Up to 8/1 */
189 #define INPUT_RATE_MAX      8000            /* Up to 1/8 */
190
191 /* input_source_t: gathers all information per input source */
192 typedef struct
193 {
194     /* Input item description */
195     input_item_t *p_item;
196
197     /* Access/Stream/Demux plugins */
198     access_t *p_access;
199     stream_t *p_stream;
200     demux_t  *p_demux;
201
202     /* Title infos for that input */
203     vlc_bool_t   b_title_demux; /* Titles/Seekpoints provided by demux */
204     int          i_title;
205     input_title_t **title;
206
207     int i_title_offset;
208     int i_seekpoint_offset;
209
210     int i_title_start;
211     int i_title_end;
212     int i_seekpoint_start;
213     int i_seekpoint_end;
214
215     /* Properties */
216     vlc_bool_t b_can_pace_control;
217     vlc_bool_t b_can_pause;
218     vlc_bool_t b_eof;   /* eof of demuxer */
219
220     /* Clock average variation */
221     int     i_cr_average;
222
223 } input_source_t;
224
225 /* i_update field of access_t/demux_t */
226 #define INPUT_UPDATE_NONE       0x0000
227 #define INPUT_UPDATE_SIZE       0x0001
228 #define INPUT_UPDATE_TITLE      0x0010
229 #define INPUT_UPDATE_SEEKPOINT  0x0020
230 #define INPUT_UPDATE_META       0x0040
231
232 /* Input control XXX: internal */
233 #define INPUT_CONTROL_FIFO_SIZE    100
234
235 /*****************************************************************************
236  * input_thread_t
237  *****************************************************************************
238  * XXX: this strucrures is *PRIVATE* so nobody can touch it out of src/input.
239  * I plan to move it to src/input/input_internal.h anyway
240  *
241  * XXX: look at src/input/input.c:input_CreateThread for accessible variables
242  *      YOU CANNOT HAVE ACCESS TO THE CONTENT OF input_thread_t except
243  *      p_input->input.p_item (and it's only temporary).
244  * XXX: move the docs somewhere (better than src/input )
245  *****************************************************************************/
246 struct input_thread_t
247 {
248     VLC_COMMON_MEMBERS
249
250      /* Global properties */
251     vlc_bool_t  b_eof;
252     vlc_bool_t  b_can_pace_control;
253     vlc_bool_t  b_can_pause;
254
255     /* Global state */
256     int         i_state;
257     int         i_rate;
258
259     /* */
260     int64_t     i_start;    /* :start-time,0 by default */
261     int64_t     i_time;     /* Current time */
262     int64_t     i_stop;     /* :stop-time, 0 if none */
263
264     /* Title infos FIXME multi-input (not easy) ? */
265     int          i_title;
266     input_title_t **title;
267
268     int i_title_offset;
269     int i_seekpoint_offset;
270
271     /* User bookmarks FIXME won't be easy with multiples input */
272     int         i_bookmark;
273     seekpoint_t **bookmark;
274
275     /* Output */
276     es_out_t    *p_es_out;
277     sout_instance_t *p_sout;            /* XXX Move it to es_out ? */
278     vlc_bool_t      b_out_pace_control; /*     idem ? */
279
280     /* Internal caching common for all inputs */
281     int64_t i_pts_delay;
282
283     /* Main input properties */
284     input_source_t input;
285
286     /* Slave demuxers (subs, and others) */
287     int            i_slave;
288     input_source_t **slave;
289
290     /* Buffer of pending actions */
291     vlc_mutex_t lock_control;
292     int i_control;
293     struct
294     {
295         /* XXX: val isn't duplicated so it won't works with string */
296         int         i_type;
297         vlc_value_t val;
298     } control[INPUT_CONTROL_FIFO_SIZE];
299 };
300
301 /*****************************************************************************
302  * Prototypes
303  *****************************************************************************/
304 #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
305 VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
306 VLC_EXPORT( void,             input_StopThread,     ( input_thread_t * ) );
307 VLC_EXPORT( void,             input_DestroyThread,  ( input_thread_t * ) );
308
309 enum input_query_e
310 {
311     /* input variable "position" */
312     INPUT_GET_POSITION,         /* arg1= double *       res=    */
313     INPUT_SET_POSITION,         /* arg1= double         res=can fail    */
314
315     /* input variable "length" */
316     INPUT_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
317
318     /* input variable "time" */
319     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
320     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
321
322     /* input variable "rate" (1 is DEFAULT_RATE) */
323     INPUT_GET_RATE,             /* arg1= int *          res=    */
324     INPUT_SET_RATE,             /* arg1= int            res=can fail    */
325
326     /* input variable "state" */
327     INPUT_GET_STATE,            /* arg1= int *          res=    */
328     INPUT_SET_STATE,            /* arg1= int            res=can fail    */
329
330     /* input variable "audio-delay" and "spu-delay" */
331     INPUT_GET_AUDIO_DELAY,      /* arg1 = int* res=can fail */
332     INPUT_SET_AUDIO_DELAY,      /* arg1 = int  res=can fail */
333     INPUT_GET_SPU_DELAY,        /* arg1 = int* res=can fail */
334     INPUT_SET_SPU_DELAY,        /* arg1 = int  res=can fail */
335
336     /* Meta datas */
337     INPUT_ADD_INFO,   /* arg1= char * arg2= char * arg3=...  res=can fail    */
338     INPUT_GET_INFO,   /* arg1= char * arg2= char * arg3= char ** res=can fail*/
339     INPUT_SET_NAME,   /* arg1= char * res=can fail    */
340
341     /* Input config options */
342     INPUT_ADD_OPTION,      /* arg1= char * arg2= char *  res=can fail*/
343
344     /* Input properties */
345     INPUT_GET_BYTE_POSITION,     /* arg1= int64_t *       res=    */
346     INPUT_SET_BYTE_SIZE,         /* arg1= int64_t *       res=    */
347
348     /* bookmarks */
349     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
350     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
351     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
352     INPUT_CHANGE_BOOKMARK, /* arg1= seekpoint_t * arg2= int * res=can fail   */
353     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
354     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
355 };
356
357 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
358 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
359
360
361 VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder ) );
362 VLC_EXPORT( void, input_DecoderDelete, ( decoder_t * ) );
363 VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
364
365 #endif
366