]> git.sesse.net Git - vlc/blob - include/vlc_input.h
input: added INPUT_ADD_SLAVE to allow adding a slave input on the fly. (Don't use...
[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_id;                 /**< Identifier of the item */
57     uint8_t    i_type;               /**< Type (file, disc, ...) */
58
59     int        i_categories;         /**< Number of info categories */
60     info_category_t **pp_categories; /**< Pointer to the first info category */
61
62     int         i_es;                /**< Number of es format descriptions */
63     es_format_t **es;                /**< Pointer to an array of es formats */
64
65     vlc_bool_t  b_fixed_name;        /**< Can the interface change the name ?*/
66
67     vlc_mutex_t lock;                /**< Item cannot be changed without this lock */
68 };
69
70 #define ITEM_TYPE_UNKNOWN       0
71 #define ITEM_TYPE_FILE          1
72 #define ITEM_TYPE_DIRECTORY     2
73 #define ITEM_TYPE_DISC          3
74 #define ITEM_TYPE_CARD          4
75 #define ITEM_TYPE_NET           5
76 #define ITEM_TYPE_PLAYLIST      6
77
78 static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
79 {
80     memset( p_i, 0, sizeof(input_item_t) );
81     p_i->i_options  = 0;
82     p_i->i_es = 0;
83     p_i->i_categories = 0 ;
84     p_i->psz_name = 0;
85     p_i->psz_uri = 0;
86     p_i->ppsz_options = 0;
87     p_i->pp_categories = 0;
88     p_i->es = 0;
89     p_i->i_type = ITEM_TYPE_UNKNOWN;
90     p_i->b_fixed_name = VLC_TRUE;
91     vlc_mutex_init( p_o, &p_i->lock );
92 }
93
94 static inline void vlc_input_item_CopyOptions( input_item_t *p_parent,
95                                                input_item_t *p_child )
96 {
97     int i;
98     for( i = 0 ; i< p_parent->i_options; i++ )
99     {
100         char *psz_option= strdup( p_parent->ppsz_options[i] );
101         p_child->i_options++;
102         p_child->ppsz_options = (char **)realloc( p_child->ppsz_options,
103                                                   p_child->i_options *
104                                                   sizeof( char * ) );
105         p_child->ppsz_options[p_child->i_options-1] = psz_option;
106     }
107 }
108
109 static inline void vlc_input_item_Clean( input_item_t *p_i )
110 {
111     if( p_i->psz_name ) free( p_i->psz_name );
112     if( p_i->psz_uri ) free( p_i->psz_uri );
113     p_i->psz_name = 0;
114     p_i->psz_uri = 0;
115
116     while( p_i->i_options )
117     {
118         p_i->i_options--;
119         if( p_i->ppsz_options[p_i->i_options] )
120             free( p_i->ppsz_options[p_i->i_options] );
121         if( !p_i->i_options ) free( p_i->ppsz_options );
122     }
123
124     while( p_i->i_es )
125     {
126         p_i->i_es--;
127         es_format_Clean( p_i->es[p_i->i_es] );
128         if( !p_i->i_es ) free( p_i->es );
129     }
130
131     while( p_i->i_categories )
132     {
133         info_category_t *p_category =
134             p_i->pp_categories[--(p_i->i_categories)];
135
136         while( p_category->i_infos )
137         {
138             p_category->i_infos--;
139
140             if( p_category->pp_infos[p_category->i_infos]->psz_name )
141                 free( p_category->pp_infos[p_category->i_infos]->psz_name);
142             if( p_category->pp_infos[p_category->i_infos]->psz_value )
143                 free( p_category->pp_infos[p_category->i_infos]->psz_value );
144             free( p_category->pp_infos[p_category->i_infos] );
145
146             if( !p_category->i_infos ) free( p_category->pp_infos );
147         }
148
149         if( p_category->psz_name ) free( p_category->psz_name );
150         free( p_category );
151
152         if( !p_i->i_categories ) free( p_i->pp_categories );
153     }
154
155     vlc_mutex_destroy( &p_i->lock );
156 }
157
158 /*****************************************************************************
159  * Seek point: (generalisation of chapters)
160  *****************************************************************************/
161 struct seekpoint_t
162 {
163     int64_t i_byte_offset;
164     int64_t i_time_offset;
165     char    *psz_name;
166 };
167
168 static inline seekpoint_t *vlc_seekpoint_New( void )
169 {
170     seekpoint_t *point = (seekpoint_t*)malloc( sizeof( seekpoint_t ) );
171     point->i_byte_offset =
172     point->i_time_offset = 0;
173     point->psz_name = NULL;
174     return point;
175 }
176
177 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
178 {
179     if( !point ) return;
180     if( point->psz_name ) free( point->psz_name );
181     free( point );
182 }
183
184 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
185 {
186     seekpoint_t *point = vlc_seekpoint_New();
187     if( src->psz_name ) point->psz_name = strdup( src->psz_name );
188     point->i_time_offset = src->i_time_offset;
189     point->i_byte_offset = src->i_byte_offset;
190     return point;
191 }
192
193 /*****************************************************************************
194  * Title:
195  *****************************************************************************/
196 typedef struct
197 {
198     char        *psz_name;
199
200     vlc_bool_t  b_menu;      /* Is it a menu or a normal entry */
201
202     int64_t     i_length;   /* Length(microsecond) if known, else 0 */
203     int64_t     i_size;     /* Size (bytes) if known, else 0 */
204
205     /* Title seekpoint */
206     int         i_seekpoint;
207     seekpoint_t **seekpoint;
208
209 } input_title_t;
210
211 static inline input_title_t *vlc_input_title_New( )
212 {
213     input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
214
215     t->psz_name = NULL;
216     t->b_menu = VLC_FALSE;
217     t->i_length = 0;
218     t->i_size   = 0;
219     t->i_seekpoint = 0;
220     t->seekpoint = NULL;
221
222     return t;
223 }
224
225 static inline void vlc_input_title_Delete( input_title_t *t )
226 {
227     int i;
228     if( t == NULL )
229         return;
230
231     if( t->psz_name ) free( t->psz_name );
232     for( i = 0; i < t->i_seekpoint; i++ )
233     {
234         if( t->seekpoint[i]->psz_name ) free( t->seekpoint[i]->psz_name );
235         free( t->seekpoint[i] );
236     }
237     if( t->seekpoint ) free( t->seekpoint );
238     free( t );
239 }
240
241 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
242 {
243     input_title_t *dup = vlc_input_title_New( );
244     int i;
245
246     if( t->psz_name ) dup->psz_name = strdup( t->psz_name );
247     dup->b_menu      = t->b_menu;
248     dup->i_length    = t->i_length;
249     dup->i_size      = t->i_size;
250     dup->i_seekpoint = t->i_seekpoint;
251     if( t->i_seekpoint > 0 )
252     {
253         dup->seekpoint = (seekpoint_t**)calloc( t->i_seekpoint,
254                                                 sizeof(seekpoint_t*) );
255
256         for( i = 0; i < t->i_seekpoint; i++ )
257         {
258             dup->seekpoint[i] = vlc_seekpoint_Duplicate( t->seekpoint[i] );
259         }
260     }
261
262     return dup;
263 }
264
265 /*****************************************************************************
266  * input defines/constants.
267  *****************************************************************************/
268
269 /* "state" value */
270 enum input_state_e
271 {
272     INIT_S,
273     PLAYING_S,
274     PAUSE_S,
275     END_S,
276 };
277
278 /* "rate" default, min/max */
279 #define INPUT_RATE_DEFAULT  1000
280 #define INPUT_RATE_MIN       125            /* Up to 8/1 */
281 #define INPUT_RATE_MAX      8000            /* Up to 1/8 */
282
283 /* input_source_t: gathers all information per input source */
284 typedef struct
285 {
286     /* Input item description */
287     input_item_t *p_item;
288
289     /* Access/Stream/Demux plugins */
290     access_t *p_access;
291     stream_t *p_stream;
292     demux_t  *p_demux;
293
294     /* Title infos for that input */
295     vlc_bool_t   b_title_demux; /* Titles/Seekpoints provided by demux */
296     int          i_title;
297     input_title_t **title;
298
299     int i_title_offset;
300     int i_seekpoint_offset;
301
302     int i_title_start;
303     int i_title_end;
304     int i_seekpoint_start;
305     int i_seekpoint_end;
306
307     /* Properties */
308     vlc_bool_t b_can_pace_control;
309     vlc_bool_t b_can_pause;
310     vlc_bool_t b_eof;   /* eof of demuxer */
311
312     /* Clock average variation */
313     int     i_cr_average;
314
315 } input_source_t;
316
317 /* i_update field of access_t/demux_t */
318 #define INPUT_UPDATE_NONE       0x0000
319 #define INPUT_UPDATE_SIZE       0x0001
320 #define INPUT_UPDATE_TITLE      0x0010
321 #define INPUT_UPDATE_SEEKPOINT  0x0020
322 #define INPUT_UPDATE_META       0x0040
323
324 /* Input control XXX: internal */
325 #define INPUT_CONTROL_FIFO_SIZE    100
326
327 /*****************************************************************************
328  * input_thread_t
329  *****************************************************************************
330  * XXX: this strucrures is *PRIVATE* so nobody can touch it out of src/input.
331  * I plan to move it to src/input/input_internal.h anyway
332  *
333  * XXX: look at src/input/input.c:input_CreateThread for accessible variables
334  *      YOU CANNOT HAVE ACCESS TO THE CONTENT OF input_thread_t except
335  *      p_input->input.p_item (and it's only temporary).
336  * XXX: move the docs somewhere (better than src/input )
337  *****************************************************************************/
338 struct input_thread_t
339 {
340     VLC_COMMON_MEMBERS
341
342      /* Global properties */
343     vlc_bool_t  b_eof;
344     vlc_bool_t  b_can_pace_control;
345     vlc_bool_t  b_can_pause;
346
347     /* Global state */
348     int         i_state;
349     int         i_rate;
350
351     /* */
352     int64_t     i_start;    /* :start-time,0 by default */
353     int64_t     i_time;     /* Current time */
354     int64_t     i_stop;     /* :stop-time, 0 if none */
355
356     /* Title infos FIXME multi-input (not easy) ? */
357     int          i_title;
358     input_title_t **title;
359
360     int i_title_offset;
361     int i_seekpoint_offset;
362
363     /* User bookmarks FIXME won't be easy with multiples input */
364     int         i_bookmark;
365     seekpoint_t **bookmark;
366
367     /* Global meta datas FIXME move to input_item_t ? */
368     vlc_meta_t  *p_meta;
369
370     /* Output */
371     es_out_t    *p_es_out;
372     sout_instance_t *p_sout;            /* XXX Move it to es_out ? */
373     vlc_bool_t      b_out_pace_control; /*     idem ? */
374
375     /* Internal caching common for all inputs */
376     int64_t i_pts_delay;
377
378     /* Main input properties */
379     input_source_t input;
380
381     /* Slave demuxers (subs, and others) */
382     int            i_slave;
383     input_source_t **slave;
384
385     /* Buffer of pending actions */
386     vlc_mutex_t lock_control;
387     int i_control;
388     struct
389     {
390         /* XXX: val isn't duplicated so it won't works with string */
391         int         i_type;
392         vlc_value_t val;
393     } control[INPUT_CONTROL_FIFO_SIZE];
394 };
395
396 /*****************************************************************************
397  * Prototypes
398  *****************************************************************************/
399 #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
400 VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
401 VLC_EXPORT( void,             input_StopThread,     ( input_thread_t * ) );
402 VLC_EXPORT( void,             input_DestroyThread,  ( input_thread_t * ) );
403
404 enum input_query_e
405 {
406     /* input variable "position" */
407     INPUT_GET_POSITION,         /* arg1= double *       res=    */
408     INPUT_SET_POSITION,         /* arg1= double         res=can fail    */
409
410     /* input variable "length" */
411     INPUT_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
412
413     /* input variable "time" */
414     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
415     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
416
417     /* input variable "rate" (1 is DEFAULT_RATE) */
418     INPUT_GET_RATE,             /* arg1= int *          res=    */
419     INPUT_SET_RATE,             /* arg1= int            res=can fail    */
420
421     /* input variable "state" */
422     INPUT_GET_STATE,            /* arg1= int *          res=    */
423     INPUT_SET_STATE,            /* arg1= int            res=can fail    */
424
425     /* input variable "audio-delay" and "spu-delay" */
426     INPUT_GET_AUDIO_DELAY,      /* arg1 = int* res=can fail */
427     INPUT_SET_AUDIO_DELAY,      /* arg1 = int  res=can fail */
428     INPUT_GET_SPU_DELAY,        /* arg1 = int* res=can fail */
429     INPUT_SET_SPU_DELAY,        /* arg1 = int  res=can fail */
430
431     /* Meta datas */
432     INPUT_ADD_INFO,   /* arg1= char * arg2= char * arg3=...  res=can fail    */
433     INPUT_GET_INFO,   /* arg1= char * arg2= char * arg3= char ** res=can fail*/
434     INPUT_SET_NAME,   /* arg1= char * res=can fail    */
435
436     /* Input config options */
437     INPUT_ADD_OPTION,      /* arg1= char * arg2= char *  res=can fail*/
438
439     /* Input properties */
440     INPUT_GET_BYTE_POSITION,     /* arg1= int64_t *       res=    */
441     INPUT_SET_BYTE_SIZE,         /* arg1= int64_t *       res=    */
442
443     /* bookmarks */
444     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
445     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
446     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
447     INPUT_CHANGE_BOOKMARK, /* arg1= seekpoint_t * arg2= int * res=can fail   */
448     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
449     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
450
451     /* On the fly input slave */
452     INPUT_ADD_SLAVE,       /* arg1= char * */
453 };
454
455 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
456 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
457
458 VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder ) );
459 VLC_EXPORT( void, input_DecoderDelete, ( decoder_t * ) );
460 VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
461
462 #endif