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