]> git.sesse.net Git - vlc/blob - include/vlc_input.h
* include/vlc_input.h, src/playlist/item.c: added vlc_input_item_Init()/Clean() facility.
[vlc] / include / vlc_input.h
1 /*****************************************************************************
2  * vlc_input.h:
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: input_ext-intf.h 7954 2004-06-07 22:19:12Z fenrir $
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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 /*****************************************************************************
30  * input_item_t: Describes an input and is used to spawn input_thread_t objects
31  *****************************************************************************/
32 struct info_t
33 {
34     char *psz_name;            /**< Name of this info */
35     char *psz_value;           /**< Value of the info */
36 };
37
38 struct info_category_t
39 {
40     char   *psz_name;      /**< Name of this category */
41     int    i_infos;        /**< Number of infos in the category */
42     struct info_t **pp_infos;     /**< Pointer to an array of infos */
43 };
44
45 struct input_item_t
46 {
47     char       *psz_name;            /**< text describing this item */
48     char       *psz_uri;             /**< mrl of this item */
49
50     int        i_options;            /**< Number of input options */
51     char       **ppsz_options;       /**< Array of input options */
52
53     mtime_t    i_duration;           /**< A hint about the duration of this
54                                       * item, in milliseconds*/
55
56     int        i_categories;         /**< Number of info categories */
57     info_category_t **pp_categories; /**< Pointer to the first info category */
58
59     int         i_es;                /**< Number of es format descriptions */
60     es_format_t **es;                /**< Pointer to an array of es formats */
61
62     vlc_mutex_t lock;                /**< Item cannot be changed without this lock */
63 };
64
65 static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
66 {
67     memset( p_i, 0, sizeof(input_item_t) );
68     p_i->psz_name = 0;
69     p_i->psz_uri = 0;
70     p_i->ppsz_options = 0;
71     p_i->pp_categories = 0;
72     p_i->es = 0;
73     vlc_mutex_init( p_o, &p_i->lock );
74 }
75
76 static inline void vlc_input_item_Clean( input_item_t *p_i )
77 {
78     if( p_i->psz_name ) free( p_i->psz_name );
79     if( p_i->psz_uri ) free( p_i->psz_uri );
80     p_i->psz_name = 0;
81     p_i->psz_uri = 0;
82
83     while( p_i->i_options )
84     {
85         p_i->i_options--;
86         if( p_i->ppsz_options[p_i->i_options] )
87             free( p_i->ppsz_options[p_i->i_options] );
88         if( !p_i->i_options ) free( p_i->ppsz_options );
89     }
90
91     while( p_i->i_es )
92     {
93         p_i->i_es--;
94         es_format_Clean( p_i->es[p_i->i_es] );
95         if( !p_i->i_es ) free( p_i->es );
96     }
97
98     while( p_i->i_categories )
99     {
100         info_category_t *p_category =
101             p_i->pp_categories[--(p_i->i_categories)];
102
103         while( p_category->i_infos )
104         {
105             p_category->i_infos--;
106
107             if( p_category->pp_infos[p_category->i_infos]->psz_name )
108                 free( p_category->pp_infos[p_category->i_infos]->psz_name);
109             if( p_category->pp_infos[p_category->i_infos]->psz_value )
110                 free( p_category->pp_infos[p_category->i_infos]->psz_value );
111             free( p_category->pp_infos[p_category->i_infos] );
112
113             if( !p_category->i_infos ) free( p_category->pp_infos );
114         }
115
116         if( p_category->psz_name ) free( p_category->psz_name );
117         free( p_category );
118
119         if( !p_i->i_categories ) free( p_i->pp_categories );
120     }
121
122     vlc_mutex_destroy( &p_i->lock );
123 }
124
125 /*****************************************************************************
126  * Seek point: (generalisation of chapters)
127  *****************************************************************************/
128 struct seekpoint_t
129 {
130     int64_t i_byte_offset;
131     int64_t i_time_offset;
132     char    *psz_name;
133 };
134
135 static inline seekpoint_t *vlc_seekpoint_New( void )
136 {
137     seekpoint_t *point = (seekpoint_t*)malloc( sizeof( seekpoint_t ) );
138     point->i_byte_offset =
139     point->i_time_offset = 0;
140     point->psz_name = NULL;
141     return point;
142 }
143
144 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
145 {
146     if( !point ) return;
147     if( point->psz_name ) free( point->psz_name );
148     free( point );
149 }
150
151 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
152 {
153     seekpoint_t *point = vlc_seekpoint_New();
154     if( src->psz_name ) point->psz_name = strdup( src->psz_name );
155     point->i_time_offset = src->i_time_offset;
156     point->i_byte_offset = src->i_byte_offset;
157     return point;
158 }
159
160 /*****************************************************************************
161  * Title:
162  *****************************************************************************/
163 typedef struct
164 {
165     char        *psz_name;
166
167     vlc_bool_t  b_menu;      /* Is it a menu or a normal entry */
168
169     int64_t     i_length;   /* Length(microsecond) if known, else 0 */
170     int64_t     i_size;     /* Size (bytes) if known, else 0 */
171
172     /* Title seekpoint */
173     int         i_seekpoint;
174     seekpoint_t **seekpoint;
175
176 } input_title_t;
177
178 static inline input_title_t *vlc_input_title_New( )
179 {
180     input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
181
182     t->psz_name = NULL;
183     t->b_menu = VLC_FALSE;
184     t->i_length = 0;
185     t->i_size   = 0;
186     t->i_seekpoint = 0;
187     t->seekpoint = NULL;
188
189     return t;
190 }
191
192 static inline void vlc_input_title_Delete( input_title_t *t )
193 {
194     int i;
195     if( t == NULL )
196         return;
197
198     if( t->psz_name ) free( t->psz_name );
199     for( i = 0; i < t->i_seekpoint; i++ )
200     {
201         if( t->seekpoint[i]->psz_name ) free( t->seekpoint[i]->psz_name );
202         free( t->seekpoint[i] );
203     }
204     if( t->seekpoint ) free( t->seekpoint );
205     free( t );
206 }
207
208 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
209 {
210     input_title_t *dup = vlc_input_title_New( );
211     int i;
212
213     if( t->psz_name ) dup->psz_name = strdup( t->psz_name );
214     dup->b_menu      = t->b_menu;
215     dup->i_length    = t->i_length;
216     dup->i_size      = t->i_size;
217     dup->i_seekpoint = t->i_seekpoint;
218     if( t->i_seekpoint > 0 )
219     {
220         dup->seekpoint = (seekpoint_t**)calloc( t->i_seekpoint,
221                                                 sizeof(seekpoint_t*) );
222
223         for( i = 0; i < t->i_seekpoint; i++ )
224         {
225             dup->seekpoint[i] = vlc_seekpoint_Duplicate( t->seekpoint[i] );
226         }
227     }
228
229     return dup;
230 }
231
232 /*****************************************************************************
233  * input defines/constants.
234  *****************************************************************************/
235
236 /* "state" value */
237 enum input_state_e
238 {
239     INIT_S,
240     PLAYING_S,
241     PAUSE_S,
242     END_S,
243 };
244
245 /* "rate" default, min/max */
246 #define INPUT_RATE_DEFAULT  1000
247 #define INPUT_RATE_MIN       125            /* Up to 8/1 */
248 #define INPUT_RATE_MAX      8000            /* Up to 1/8 */
249
250 /* input_source_t: gathers all information per input source */
251 typedef struct
252 {
253     /* Input item description */
254     input_item_t *p_item;
255
256     /* Access/Stream/Demux plugins */
257     access_t *p_access;
258     stream_t *p_stream;
259     demux_t  *p_demux;
260
261     /* Title infos for that input */
262     vlc_bool_t   b_title_demux; /* Titles/Seekpoints provided by demux */
263     int          i_title;
264     input_title_t **title;
265
266     int i_title_offset;
267     int i_seekpoint_offset;
268
269     int i_title_start;
270     int i_title_end;
271     int i_seekpoint_start;
272     int i_seekpoint_end;
273
274     /* Properties */
275     vlc_bool_t b_can_pace_control;
276     vlc_bool_t b_can_pause;
277     vlc_bool_t b_eof;   /* eof of demuxer */
278
279     /* Clock average variation */
280     int     i_cr_average;
281
282 } input_source_t;
283
284 /* i_update field of access_t/demux_t */
285 #define INPUT_UPDATE_NONE       0x0000
286 #define INPUT_UPDATE_SIZE       0x0001
287 #define INPUT_UPDATE_TITLE      0x0010
288 #define INPUT_UPDATE_SEEKPOINT  0x0020
289 #define INPUT_UPDATE_META       0x0040
290
291 /* Input control XXX: internal */
292 #define INPUT_CONTROL_FIFO_SIZE    100
293
294 /*****************************************************************************
295  * input_thread_t
296  *****************************************************************************
297  * XXX: this strucrures is *PRIVATE* so nobody can touch it out of src/input.
298  * I plan to move it to src/input/input_internal.h anyway
299  *
300  * XXX: look at src/input/input.c:input_CreateThread for accessible variables
301  *      YOU CANNOT HAVE ACCESS TO THE CONTENT OF input_thread_t except
302  *      p_input->input.p_item (and it's only temporary).
303  * XXX: move the docs somewhere (better than src/input )
304  *****************************************************************************/
305 struct input_thread_t
306 {
307     VLC_COMMON_MEMBERS
308
309      /* Global properties */
310     vlc_bool_t  b_eof;
311     vlc_bool_t  b_can_pace_control;
312     vlc_bool_t  b_can_pause;
313
314     /* Global state */
315     int         i_state;
316     int         i_rate;
317
318     /* */
319     int64_t     i_start;    /* :start-time,0 by default */
320     int64_t     i_time;     /* Current time */
321     int64_t     i_stop;     /* :stop-time, 0 if none */
322
323     /* Title infos FIXME multi-input (not easy) ? */
324     int          i_title;
325     input_title_t **title;
326
327     int i_title_offset;
328     int i_seekpoint_offset;
329
330     /* User bookmarks FIXME won't be easy with multiples input */
331     int         i_bookmark;
332     seekpoint_t **bookmark;
333
334     /* Output */
335     es_out_t    *p_es_out;
336     sout_instance_t *p_sout;            /* XXX Move it to es_out ? */
337     vlc_bool_t      b_out_pace_control; /*     idem ? */
338
339     /* Internal caching common for all inputs */
340     int64_t i_pts_delay;
341
342     /* Main input properties */
343     input_source_t input;
344
345     /* Slave demuxers (subs, and others) */
346     int            i_slave;
347     input_source_t **slave;
348
349     /* Buffer of pending actions */
350     vlc_mutex_t lock_control;
351     int i_control;
352     struct
353     {
354         /* XXX: val isn't duplicated so it won't works with string */
355         int         i_type;
356         vlc_value_t val;
357     } control[INPUT_CONTROL_FIFO_SIZE];
358 };
359
360 /*****************************************************************************
361  * Prototypes
362  *****************************************************************************/
363 #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
364 VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
365 VLC_EXPORT( void,             input_StopThread,     ( input_thread_t * ) );
366 VLC_EXPORT( void,             input_DestroyThread,  ( input_thread_t * ) );
367
368 enum input_query_e
369 {
370     /* input variable "position" */
371     INPUT_GET_POSITION,         /* arg1= double *       res=    */
372     INPUT_SET_POSITION,         /* arg1= double         res=can fail    */
373
374     /* input variable "length" */
375     INPUT_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
376
377     /* input variable "time" */
378     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
379     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
380
381     /* input variable "rate" (1 is DEFAULT_RATE) */
382     INPUT_GET_RATE,             /* arg1= int *          res=    */
383     INPUT_SET_RATE,             /* arg1= int            res=can fail    */
384
385     /* input variable "state" */
386     INPUT_GET_STATE,            /* arg1= int *          res=    */
387     INPUT_SET_STATE,            /* arg1= int            res=can fail    */
388
389     /* input variable "audio-delay" and "spu-delay" */
390     INPUT_GET_AUDIO_DELAY,      /* arg1 = int* res=can fail */
391     INPUT_SET_AUDIO_DELAY,      /* arg1 = int  res=can fail */
392     INPUT_GET_SPU_DELAY,        /* arg1 = int* res=can fail */
393     INPUT_SET_SPU_DELAY,        /* arg1 = int  res=can fail */
394
395     /* Meta datas */
396     INPUT_ADD_INFO,   /* arg1= char * arg2= char * arg3=...  res=can fail    */
397     INPUT_GET_INFO,   /* arg1= char * arg2= char * arg3= char ** res=can fail*/
398     INPUT_SET_NAME,   /* arg1= char * res=can fail    */
399
400     /* Input config options */
401     INPUT_ADD_OPTION,      /* arg1= char * arg2= char *  res=can fail*/
402
403     /* Input properties */
404     INPUT_GET_BYTE_POSITION,     /* arg1= int64_t *       res=    */
405     INPUT_SET_BYTE_SIZE,         /* arg1= int64_t *       res=    */
406
407     /* bookmarks */
408     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
409     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
410     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
411     INPUT_CHANGE_BOOKMARK, /* arg1= seekpoint_t * arg2= int * res=can fail   */
412     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
413     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
414 };
415
416 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
417 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
418
419 VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vlc_bool_t b_force_decoder ) );
420 VLC_EXPORT( void, input_DecoderDelete, ( decoder_t * ) );
421 VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
422
423 #endif