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