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