]> git.sesse.net Git - vlc/blob - include/vlc_input.h
Forgot this
[vlc] / include / vlc_input.h
1 /*****************************************************************************
2  * vlc_input.h: Core input structures
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 #include <vlc_playlist.h>
30 #include <vlc_meta.h>
31
32 struct vlc_meta_t;
33
34 /*****************************************************************************
35  * input_item_t: Describes an input and is used to spawn input_thread_t objects
36  *****************************************************************************/
37 struct info_t
38 {
39     char *psz_name;            /**< Name of this info */
40     char *psz_value;           /**< Value of the info */
41 };
42
43 struct info_category_t
44 {
45     char   *psz_name;      /**< Name of this category */
46     int    i_infos;        /**< Number of infos in the category */
47     struct info_t **pp_infos;     /**< Pointer to an array of infos */
48 };
49
50 struct input_item_t
51 {
52     VLC_GC_MEMBERS
53     int        i_id;                 /**< Identifier of the item */
54
55     char       *psz_name;            /**< text describing this item */
56     char       *psz_uri;             /**< mrl of this item */
57     vlc_bool_t  b_fixed_name;        /**< Can the interface change the name ?*/
58
59     int        i_options;            /**< Number of input options */
60     char       **ppsz_options;       /**< Array of input options */
61
62     mtime_t    i_duration;           /**< Duration in milliseconds*/
63
64     uint8_t    i_type;               /**< Type (file, disc, ...) */
65
66     int        i_categories;         /**< Number of info categories */
67     info_category_t **pp_categories; /**< Pointer to the first info category */
68
69     int         i_es;                /**< Number of es format descriptions */
70     es_format_t **es;                /**< Es formats */
71
72     input_stats_t *p_stats;          /**< Statistics */
73     int           i_nb_played;       /**< Number of times played */
74
75     vlc_meta_t *p_meta;
76
77     vlc_mutex_t lock;                /**< Lock for the item */
78 };
79
80 #define ITEM_TYPE_UNKNOWN       0
81 #define ITEM_TYPE_AFILE         1
82 #define ITEM_TYPE_VFILE         2
83 #define ITEM_TYPE_DIRECTORY     3
84 #define ITEM_TYPE_DISC          4
85 #define ITEM_TYPE_CDDA          5
86 #define ITEM_TYPE_CARD          6
87 #define ITEM_TYPE_NET           7
88 #define ITEM_TYPE_PLAYLIST      8
89 #define ITEM_TYPE_NODE          9
90 #define ITEM_TYPE_NUMBER        10
91
92 static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
93 {
94     memset( p_i, 0, sizeof(input_item_t) );
95     p_i->psz_name = 0;
96     p_i->psz_uri = 0;
97     p_i->i_es = 0;
98     p_i->es = 0;
99     p_i->i_options  = 0;
100     p_i->ppsz_options = 0;
101     p_i->i_categories = 0 ;
102     p_i->pp_categories = 0;
103     p_i->i_type = ITEM_TYPE_UNKNOWN;
104     p_i->b_fixed_name = VLC_TRUE;
105
106     p_i->p_stats = (input_stats_t*) malloc( sizeof( input_stats_t ) );
107     p_i->p_meta = NULL;
108     vlc_mutex_init( p_o, &p_i->p_stats->lock );
109
110     vlc_mutex_init( p_o, &p_i->lock );
111 }
112
113 static inline void vlc_input_item_CopyOptions( input_item_t *p_parent,
114                                                input_item_t *p_child )
115 {
116     int i;
117     for( i = 0 ; i< p_parent->i_options; i++ )
118     {
119         char *psz_option= strdup( p_parent->ppsz_options[i] );
120         p_child->i_options++;
121         p_child->ppsz_options = (char **)realloc( p_child->ppsz_options,
122                                                   p_child->i_options *
123                                                   sizeof( char * ) );
124         p_child->ppsz_options[p_child->i_options-1] = psz_option;
125     }
126 }
127
128 VLC_EXPORT( void, vlc_input_item_AddOption, ( input_item_t *p_input, const char *psz_option ) );
129
130 static inline void vlc_input_item_Clean( input_item_t *p_i )
131 {
132     if( p_i->psz_name ) free( p_i->psz_name );
133     if( p_i->psz_uri ) free( p_i->psz_uri );
134     if( p_i->p_stats ) free( p_i->p_stats );
135     p_i->psz_name = 0;
136     p_i->psz_uri = 0;
137
138     if( p_i->p_meta ) vlc_meta_Delete( p_i->p_meta );
139
140     while( p_i->i_options )
141     {
142         p_i->i_options--;
143         if( p_i->ppsz_options[p_i->i_options] )
144             free( p_i->ppsz_options[p_i->i_options] );
145         if( !p_i->i_options ) free( p_i->ppsz_options );
146     }
147
148     while( p_i->i_es )
149     {
150         p_i->i_es--;
151         es_format_Clean( p_i->es[p_i->i_es] );
152         if( !p_i->i_es ) free( p_i->es );
153     }
154
155     while( p_i->i_categories )
156     {
157         info_category_t *p_category =
158             p_i->pp_categories[--(p_i->i_categories)];
159
160         while( p_category->i_infos )
161         {
162             p_category->i_infos--;
163
164             if( p_category->pp_infos[p_category->i_infos]->psz_name )
165                 free( p_category->pp_infos[p_category->i_infos]->psz_name);
166             if( p_category->pp_infos[p_category->i_infos]->psz_value )
167                 free( p_category->pp_infos[p_category->i_infos]->psz_value );
168             free( p_category->pp_infos[p_category->i_infos] );
169
170             if( !p_category->i_infos ) free( p_category->pp_infos );
171         }
172
173         if( p_category->psz_name ) free( p_category->psz_name );
174         free( p_category );
175
176         if( !p_i->i_categories ) free( p_i->pp_categories );
177     }
178
179     vlc_mutex_destroy( &p_i->lock );
180 }
181
182 VLC_EXPORT( char *, vlc_input_item_GetInfo, ( input_item_t *p_i, const char *psz_cat,const char *psz_name ) );
183 VLC_EXPORT(int, vlc_input_item_AddInfo, ( input_item_t *p_i, const char *psz_cat, const char *psz_name, const char *psz_format, ... ) );
184
185 #define input_ItemNew( a,b,c ) input_ItemNewExt( a, b, c, 0, NULL, -1 )
186 #define input_ItemNewExt(a,b,c,d,e,f) __input_ItemNewExt( VLC_OBJECT(a),b,c,d,e,f)
187 VLC_EXPORT( input_item_t *, __input_ItemNewExt, (vlc_object_t *, const char *, const char*, int, const char **, int)  );
188 VLC_EXPORT( input_item_t *, input_ItemNewWithType, ( vlc_object_t *, const char *, const char *e, int, const char **, int, int ) );
189
190 VLC_EXPORT( input_item_t *, input_ItemGetById, (playlist_t *, int ) );
191
192
193 /*****************************************************************************
194  * Seek point: (generalisation of chapters)
195  *****************************************************************************/
196 struct seekpoint_t
197 {
198     int64_t i_byte_offset;
199     int64_t i_time_offset;
200     char    *psz_name;
201     int     i_level;
202 };
203
204 static inline seekpoint_t *vlc_seekpoint_New( void )
205 {
206     seekpoint_t *point = (seekpoint_t*)malloc( sizeof( seekpoint_t ) );
207     point->i_byte_offset =
208     point->i_time_offset = -1;
209     point->i_level = 0;
210     point->psz_name = NULL;
211     return point;
212 }
213
214 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
215 {
216     if( !point ) return;
217     if( point->psz_name ) free( point->psz_name );
218     free( point );
219 }
220
221 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
222 {
223     seekpoint_t *point = vlc_seekpoint_New();
224     if( src->psz_name ) point->psz_name = strdup( src->psz_name );
225     point->i_time_offset = src->i_time_offset;
226     point->i_byte_offset = src->i_byte_offset;
227     return point;
228 }
229
230 /*****************************************************************************
231  * Title:
232  *****************************************************************************/
233 typedef struct
234 {
235     char        *psz_name;
236
237     vlc_bool_t  b_menu;      /* Is it a menu or a normal entry */
238
239     int64_t     i_length;   /* Length(microsecond) if known, else 0 */
240     int64_t     i_size;     /* Size (bytes) if known, else 0 */
241
242     /* Title seekpoint */
243     int         i_seekpoint;
244     seekpoint_t **seekpoint;
245
246 } input_title_t;
247
248 static inline input_title_t *vlc_input_title_New( )
249 {
250     input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
251
252     t->psz_name = NULL;
253     t->b_menu = VLC_FALSE;
254     t->i_length = 0;
255     t->i_size   = 0;
256     t->i_seekpoint = 0;
257     t->seekpoint = NULL;
258
259     return t;
260 }
261
262 static inline void vlc_input_title_Delete( input_title_t *t )
263 {
264     int i;
265     if( t == NULL )
266         return;
267
268     if( t->psz_name ) free( t->psz_name );
269     for( i = 0; i < t->i_seekpoint; i++ )
270     {
271         if( t->seekpoint[i]->psz_name ) free( t->seekpoint[i]->psz_name );
272         free( t->seekpoint[i] );
273     }
274     if( t->seekpoint ) free( t->seekpoint );
275     free( t );
276 }
277
278 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
279 {
280     input_title_t *dup = vlc_input_title_New( );
281     int i;
282
283     if( t->psz_name ) dup->psz_name = strdup( t->psz_name );
284     dup->b_menu      = t->b_menu;
285     dup->i_length    = t->i_length;
286     dup->i_size      = t->i_size;
287     dup->i_seekpoint = t->i_seekpoint;
288     if( t->i_seekpoint > 0 )
289     {
290         dup->seekpoint = (seekpoint_t**)calloc( t->i_seekpoint,
291                                                 sizeof(seekpoint_t*) );
292
293         for( i = 0; i < t->i_seekpoint; i++ )
294         {
295             dup->seekpoint[i] = vlc_seekpoint_Duplicate( t->seekpoint[i] );
296         }
297     }
298
299     return dup;
300 }
301
302 /*****************************************************************************
303  * input defines/constants.
304  *****************************************************************************/
305
306 /* "state" value */
307 enum input_state_e
308 {
309     INIT_S,
310     PLAYING_S,
311     PAUSE_S,
312     END_S
313 };
314
315 /* "rate" default, min/max
316  * A rate below 1000 plays the movie faster,
317  * A rate above 1000 plays the movie slower.
318  */
319 #define INPUT_RATE_DEFAULT  1000
320 #define INPUT_RATE_MIN       125            /* Up to 8/1 */
321 #define INPUT_RATE_MAX      8000            /* Up to 1/8 */
322
323 /* input_source_t: gathers all information per input source */
324 typedef struct
325 {
326     /* Input item description */
327     input_item_t *p_item;
328
329     /* Access/Stream/Demux plugins */
330     access_t *p_access;
331     stream_t *p_stream;
332     demux_t  *p_demux;
333
334     /* Title infos for that input */
335     vlc_bool_t   b_title_demux; /* Titles/Seekpoints provided by demux */
336     int          i_title;
337     input_title_t **title;
338
339     int i_title_offset;
340     int i_seekpoint_offset;
341
342     int i_title_start;
343     int i_title_end;
344     int i_seekpoint_start;
345     int i_seekpoint_end;
346
347     /* Properties */
348     vlc_bool_t b_can_pace_control;
349     vlc_bool_t b_can_pause;
350     vlc_bool_t b_eof;   /* eof of demuxer */
351
352     /* Clock average variation */
353     int     i_cr_average;
354
355 } input_source_t;
356
357 /* i_update field of access_t/demux_t */
358 #define INPUT_UPDATE_NONE       0x0000
359 #define INPUT_UPDATE_SIZE       0x0001
360 #define INPUT_UPDATE_TITLE      0x0010
361 #define INPUT_UPDATE_SEEKPOINT  0x0020
362 #define INPUT_UPDATE_META       0x0040
363
364 /* Input control XXX: internal */
365 #define INPUT_CONTROL_FIFO_SIZE    100
366
367 /*****************************************************************************
368  * input_thread_t
369  *****************************************************************************
370  * XXX: this strucrures is *PRIVATE* so nobody can touch it out of src/input.
371  * I plan to move it to src/input/input_internal.h anyway
372  *
373  * XXX: look at src/input/input.c:input_CreateThread for accessible variables
374  *      YOU CANNOT HAVE ACCESS TO THE CONTENT OF input_thread_t except
375  *      p_input->input.p_item (and it's only temporary).
376  * XXX: move the docs somewhere (better than src/input )
377  *****************************************************************************/
378 struct input_thread_t
379 {
380     VLC_COMMON_MEMBERS
381
382      /* Global properties */
383     vlc_bool_t  b_eof;
384     vlc_bool_t  b_can_pace_control;
385     vlc_bool_t  b_can_pause;
386
387     /* Global state */
388     int         i_state;
389     int         i_rate;
390
391     /* */
392     int64_t     i_start;    /* :start-time,0 by default */
393     int64_t     i_time;     /* Current time */
394     int64_t     i_stop;     /* :stop-time, 0 if none */
395
396     /* Title infos FIXME multi-input (not easy) ? */
397     int          i_title;
398     input_title_t **title;
399
400     int i_title_offset;
401     int i_seekpoint_offset;
402
403     /* User bookmarks FIXME won't be easy with multiples input */
404     int         i_bookmark;
405     seekpoint_t **bookmark;
406
407     /* Global meta datas FIXME move to input_item_t ? */
408     vlc_meta_t  *p_meta;
409
410     /* Output */
411     es_out_t    *p_es_out;
412     sout_instance_t *p_sout;            /* XXX Move it to es_out ? */
413     vlc_bool_t      b_out_pace_control; /*     idem ? */
414
415     /* Internal caching common for all inputs */
416     int64_t i_pts_delay;
417
418     /* Main input properties */
419     input_source_t input;
420
421     /* Slave demuxers (subs, and others) */
422     int            i_slave;
423     input_source_t **slave;
424
425     /* Stats counters */
426     struct {
427         counter_t *p_read_packets;
428         counter_t *p_read_bytes;
429         counter_t *p_input_bitrate;
430         counter_t *p_demux_read;
431         counter_t *p_demux_bitrate;
432         counter_t *p_decoded_audio;
433         counter_t *p_decoded_video;
434         counter_t *p_decoded_sub;
435         counter_t *p_sout_sent_packets;
436         counter_t *p_sout_sent_bytes;
437         counter_t *p_sout_send_bitrate;
438         counter_t *p_played_abuffers;
439         counter_t *p_lost_abuffers;
440         counter_t *p_displayed_pictures;
441         counter_t *p_lost_pictures;
442         vlc_mutex_t counters_lock;
443     } counters;
444
445     /* Buffer of pending actions */
446     vlc_mutex_t lock_control;
447     int i_control;
448     struct
449     {
450         /* XXX: val isn't duplicated so it won't works with string */
451         int         i_type;
452         vlc_value_t val;
453     } control[INPUT_CONTROL_FIFO_SIZE];
454 };
455
456 /*****************************************************************************
457  * Prototypes
458  *****************************************************************************/
459 #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
460 VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
461 #define input_CreateThread2(a,b,c) __input_CreateThread2(VLC_OBJECT(a),b,c)
462 VLC_EXPORT( input_thread_t *, __input_CreateThread2, ( vlc_object_t *, input_item_t *, char * ) );
463 #define input_Preparse(a,b) __input_Preparse(VLC_OBJECT(a),b)
464 VLC_EXPORT( int, __input_Preparse, ( vlc_object_t *, input_item_t * ) );
465
466 #define input_Read(a,b,c) __input_Read(VLC_OBJECT(a),b, c)
467 VLC_EXPORT( int, __input_Read, ( vlc_object_t *, input_item_t *, vlc_bool_t ) );
468 VLC_EXPORT( void,             input_StopThread,     ( input_thread_t * ) );
469 VLC_EXPORT( void,             input_DestroyThread,  ( input_thread_t * ) );
470
471 enum input_query_e
472 {
473     /* input variable "position" */
474     INPUT_GET_POSITION,         /* arg1= double *       res=    */
475     INPUT_SET_POSITION,         /* arg1= double         res=can fail    */
476
477     /* input variable "length" */
478     INPUT_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
479
480     /* input variable "time" */
481     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
482     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
483
484     /* input variable "rate" (1 is DEFAULT_RATE) */
485     INPUT_GET_RATE,             /* arg1= int *          res=    */
486     INPUT_SET_RATE,             /* arg1= int            res=can fail    */
487
488     /* input variable "state" */
489     INPUT_GET_STATE,            /* arg1= int *          res=    */
490     INPUT_SET_STATE,            /* arg1= int            res=can fail    */
491
492     /* input variable "audio-delay" and "sub-delay" */
493     INPUT_GET_AUDIO_DELAY,      /* arg1 = int* res=can fail */
494     INPUT_SET_AUDIO_DELAY,      /* arg1 = int  res=can fail */
495     INPUT_GET_SPU_DELAY,        /* arg1 = int* res=can fail */
496     INPUT_SET_SPU_DELAY,        /* arg1 = int  res=can fail */
497
498     /* Meta datas */
499     INPUT_ADD_INFO,   /* arg1= char* arg2= char* arg3=...     res=can fail */
500     INPUT_GET_INFO,   /* arg1= char* arg2= char* arg3= char** res=can fail */
501     INPUT_DEL_INFO,   /* arg1= char* arg2= char*              res=can fail */
502     INPUT_SET_NAME,   /* arg1= char* res=can fail    */
503
504     /* Input config options */
505     INPUT_ADD_OPTION,      /* arg1= char * arg2= char *  res=can fail*/
506
507     /* Input properties */
508     INPUT_GET_BYTE_POSITION,     /* arg1= int64_t *       res=    */
509     INPUT_SET_BYTE_SIZE,         /* arg1= int64_t *       res=    */
510
511     /* bookmarks */
512     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
513     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
514     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
515     INPUT_CHANGE_BOOKMARK, /* arg1= seekpoint_t * arg2= int * res=can fail   */
516     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
517     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
518
519     /* On the fly input slave */
520     INPUT_ADD_SLAVE        /* arg1= char * */
521 };
522
523 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
524 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
525
526 VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder ) );
527 VLC_EXPORT( void, input_DecoderDelete, ( decoder_t * ) );
528 VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
529
530 VLC_EXPORT( vlc_bool_t, input_AddSubtitles, ( input_thread_t *, char *, vlc_bool_t ) );
531
532 #endif