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