]> git.sesse.net Git - vlc/blob - include/ninput.h
* all: a few changes in access2 (added a info field to access_t, remove
[vlc] / include / ninput.h
1 /*****************************************************************************
2  * ninput.h
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef _NINPUT_H
25 #define _NINPUT_H 1
26
27 #include "vlc_es.h"
28
29 /* Seek point */
30 struct seekpoint_t
31 {
32     int64_t i_byte_offset;
33     int64_t i_time_offset;
34     char    *psz_name;
35 };
36
37 static inline seekpoint_t *vlc_seekpoint_New( void )
38 {
39     seekpoint_t *point = (seekpoint_t*)malloc( sizeof( seekpoint_t ) );
40     point->i_byte_offset =
41     point->i_time_offset = 0;
42     point->psz_name = NULL;
43     return point;
44 }
45
46 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
47 {
48     if( !point ) return;
49     if( point->psz_name ) free( point->psz_name );
50     free( point );
51 }
52
53 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
54 {
55     seekpoint_t *point = vlc_seekpoint_New();
56     if( src->psz_name ) point->psz_name = strdup( src->psz_name );
57     point->i_time_offset = src->i_time_offset;
58     point->i_byte_offset = src->i_byte_offset;
59     return point;
60 }
61
62 typedef struct
63 {
64     vlc_bool_t  b_menu;      /* Is it a menu or a normal entry */
65     int64_t     i_length;    /* length if known, else 0 */
66     int         i_seekpoints;/* How many seekpoint, (0/1 has same meaning)*/
67
68     char        *psz_name;
69 } input_title_t;
70
71 static inline input_title_t *vlc_input_title_New( )
72 {
73     input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
74
75     t->b_menu = VLC_FALSE;
76     t->i_length = 0;
77     t->i_seekpoints = 0;
78     t->psz_name = NULL;
79
80     return t;
81 }
82 static inline void vlc_input_title_Delete( input_title_t *t )
83 {
84     if( t )
85     {
86         if( t->psz_name ) free( t->psz_name );
87         free( t );
88     }
89 }
90
91 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
92 {
93     input_title_t *dup = vlc_input_title_New( );
94
95     dup->b_menu      = t->b_menu;
96     dup->i_length    = t->i_length;
97     dup->i_seekpoints= t->i_seekpoints;
98     if( t->psz_name ) dup->psz_name = strdup( t->psz_name );
99
100     return dup;
101 }
102
103 /**
104  * \defgroup es out Es Out
105  * @{
106  */
107
108 enum es_out_mode_e
109 {
110     ES_OUT_MODE_NONE,   /* don't select anything */
111     ES_OUT_MODE_ALL,    /* eg for stream output */
112     ES_OUT_MODE_AUTO    /* best audio/video or for input follow audio-channel, spu-channel */
113 };
114
115 enum es_out_query_e
116 {
117     /* activate apply of mode */
118     ES_OUT_SET_ACTIVE,  /* arg1= vlc_bool_t                     */
119     /* see if mode is currently aplied or not */
120     ES_OUT_GET_ACTIVE,  /* arg1= vlc_bool_t*                    */
121
122     /* set/get mode */
123     ES_OUT_SET_MODE,    /* arg1= int                            */
124     ES_OUT_GET_MODE,    /* arg2= int*                           */
125
126     /* set es selected for the es category(audio/video/spu) */
127     ES_OUT_SET_ES,      /* arg1= es_out_id_t*                   */
128
129     /* force selection/unselection of the ES (bypass current mode)*/
130     ES_OUT_SET_ES_STATE,/* arg1= es_out_id_t* arg2=vlc_bool_t   */
131     ES_OUT_GET_ES_STATE,/* arg1= es_out_id_t* arg2=vlc_bool_t*  */
132
133     /* PCR handling, by default dts/pts will be automatically computed using thoses PCR */
134     ES_OUT_SET_PCR,             /* arg1=int64_t i_pcr(microsecond!) (using default group 0)*/
135     ES_OUT_SET_GROUP_PCR,       /* arg1= int i_group, arg2=int64_t i_pcr(microsecond!)*/
136     ES_OUT_RESET_PCR,           /* no arg */
137 };
138
139 struct es_out_t
140 {
141     es_out_id_t *(*pf_add)    ( es_out_t *, es_format_t * );
142     int          (*pf_send)   ( es_out_t *, es_out_id_t *, block_t * );
143     void         (*pf_del)    ( es_out_t *, es_out_id_t * );
144     int          (*pf_control)( es_out_t *, int i_query, va_list );
145
146     es_out_sys_t    *p_sys;
147 };
148
149 static inline es_out_id_t * es_out_Add( es_out_t *out, es_format_t *fmt )
150 {
151     return out->pf_add( out, fmt );
152 }
153 static inline void es_out_Del( es_out_t *out, es_out_id_t *id )
154 {
155     out->pf_del( out, id );
156 }
157 static inline int es_out_Send( es_out_t *out, es_out_id_t *id,
158                                block_t *p_block )
159 {
160     return out->pf_send( out, id, p_block );
161 }
162
163 static inline int es_out_vaControl( es_out_t *out, int i_query, va_list args )
164 {
165     return out->pf_control( out, i_query, args );
166 }
167 static inline int es_out_Control( es_out_t *out, int i_query, ... )
168 {
169     va_list args;
170     int     i_result;
171
172     va_start( args, i_query );
173     i_result = es_out_vaControl( out, i_query, args );
174     va_end( args );
175     return i_result;
176 }
177
178 /**
179  * @}
180  */
181
182 /* i_update field of access_t/demux_t */
183 #define INPUT_UPDATE_NONE       0x0000
184 #define INPUT_UPDATE_SIZE       0x0001
185 #define INPUT_UPDATE_TITLE      0x0010
186 #define INPUT_UPDATE_SEEKPOINT  0x0020
187
188 /**
189  * \defgroup access Access
190  * @{
191  */
192
193 enum access_query_e
194 {
195     /* capabilities */
196     ACCESS_CAN_SEEK,        /* arg1= vlc_bool_t*    cannot fail */
197     ACCESS_CAN_FASTSEEK,    /* arg1= vlc_bool_t*    cannot fail */
198     ACCESS_CAN_PAUSE,       /* arg1= vlc_bool_t*    cannot fail */
199     ACCESS_CAN_CONTROL_PACE,/* arg1= vlc_bool_t*    cannot fail */
200
201     /* */
202     ACCESS_GET_MTU,         /* arg1= int*           cannot fail(0 if no sense)*/
203     ACCESS_GET_PTS_DELAY,   /* arg1= int64_t*       cannot fail */
204     /* */
205     ACCESS_GET_TITLE_INFO,      /* arg1=input_title_t*** arg2=int* can fail */
206     ACCESS_GET_SEEKPOINT_INFO,  /* arg1=seekpoint_t ***  arg2=int* can fail */
207
208     /* */
209     ACCESS_SET_PAUSE_STATE, /* arg1= vlc_bool_t     can fail */
210
211     /* */
212     ACCESS_SET_TITLE,       /* arg1= int            can fail */
213     ACCESS_SET_SEEKPOINT,   /* arg1= int            can fail */
214 };
215
216 struct access_t
217 {
218     VLC_COMMON_MEMBERS
219
220     /* Module properties */
221     module_t    *p_module;
222
223     /* Access name (empty if non forced) */
224     char        *psz_access;
225     char        *psz_path;
226     /* Access can fill this entry to force a demuxer */
227     char        *psz_demux;
228
229     /* set by access (only one of pf_read/pf_block may be filled) */
230     int         (*pf_read) ( access_t *, uint8_t *, int );  /* Return -1 if no data yet, 0 if no more data, else real data read */
231     block_t    *(*pf_block)( access_t * );                  /* return a block of data in his 'natural' size */
232     int         (*pf_seek) ( access_t *, int64_t );         /* can be null if can't seek */
233
234     int         (*pf_control)( access_t *, int i_query, va_list args);  /* mandatory */
235
236     /* access has to maintain them uptodate */
237     struct
238     {
239         unsigned int i_update;  /* Access sets them on change,
240                                    Input removes them once take into account*/
241
242         int64_t      i_size;    /* Write only for access, read only for input */
243         int64_t      i_pos;     /* idem */
244         vlc_bool_t   b_eof;     /* idem */
245
246         int          i_title;    /* idem, start from 0 (could be menu) */
247         int          i_seekpoint;/* idem, start from 0 */
248     } info;
249     access_sys_t *p_sys;
250 };
251
252 #define access2_New( a, b ) __access2_New(VLC_OBJECT(a), b )
253 VLC_EXPORT( access_t *, __access2_New,  ( vlc_object_t *p_obj, char *psz_mrl ) );
254 VLC_EXPORT( void,      access2_Delete, ( access_t * ) );
255
256 static inline int access2_vaControl( access_t *p_access, int i_query, va_list args )
257 {
258     return p_access->pf_control( p_access, i_query, args );
259 }
260 static inline int access2_Control( access_t *p_access, int i_query, ... )
261 {
262     va_list args;
263     int     i_result;
264
265     va_start( args, i_query );
266     i_result = access2_vaControl( p_access, i_query, args );
267     va_end( args );
268     return i_result;
269 }
270
271 /**
272  * @}
273  */
274
275 /**
276  * \defgroup stream Stream
277  *
278  *  This will allow you to easily handle read/seek in demuxer modules.
279  * @{
280  */
281
282 /**
283  * Possible commands to send to stream_Control() and stream_vaControl()
284  */
285 enum stream_query_e
286 {
287     /* capabilities */
288     STREAM_CAN_SEEK,            /**< arg1= vlc_bool_t *   res=cannot fail*/
289     STREAM_CAN_FASTSEEK,        /**< arg1= vlc_bool_t *   res=cannot fail*/
290
291     /* */
292     STREAM_SET_POSITION,        /**< arg1= int64_t        res=can fail  */
293     STREAM_GET_POSITION,        /**< arg1= int64_t *      res=cannot fail*/
294
295     STREAM_GET_SIZE,            /**< arg1= int64_t *      res=cannot fail (0 if no sense)*/
296
297     STREAM_GET_MTU              /**< arg1= int *          res=cannot fail (0 if no sense)*/
298 };
299
300 /**
301  * stream_t definition
302  */
303 struct stream_t
304 {
305     VLC_COMMON_MEMBERS
306
307     block_t *(*pf_block)  ( stream_t *, int i_size );
308     int      (*pf_read)   ( stream_t *, void *p_read, int i_read );
309     int      (*pf_peek)   ( stream_t *, uint8_t **pp_peek, int i_peek );
310     int      (*pf_control)( stream_t *, int i_query, va_list );
311
312     stream_sys_t *p_sys;
313 };
314
315 /**
316  * Try to read "i_read" bytes into a buffer pointed by "p_read".  If
317  * "p_read" is NULL then data are skipped instead of read.  The return
318  * value is the real numbers of bytes read/skip. If this value is less
319  * than i_read that means that it's the end of the stream.
320  */
321 static inline int stream_Read( stream_t *s, void *p_read, int i_read )
322 {
323     return s->pf_read( s, p_read, i_read );
324 }
325
326 /**
327  * Store in pp_peek a pointer to the next "i_peek" bytes in the stream
328  * \return The real numbers of valid bytes, if it's less
329  * or equal to 0, *pp_peek is invalid.
330  * \note pp_peek is a pointer to internal buffer and it will be invalid as
331  * soons as other stream_* functions are called.
332  * \note Due to input limitation, it could be less than i_peek without meaning
333  * the end of the stream (but only when you have i_peek >=
334  * p_input->i_bufsize)
335  */
336 static inline int stream_Peek( stream_t *s, uint8_t **pp_peek, int i_peek )
337 {
338     return s->pf_peek( s, pp_peek, i_peek );
339 }
340
341 /**
342  * Use to control the "stream_t *". Look at #stream_query_e for
343  * possible "i_query" value and format arguments.  Return VLC_SUCCESS
344  * if ... succeed ;) and VLC_EGENERIC if failed or unimplemented
345  */
346 static inline int stream_vaControl( stream_t *s, int i_query, va_list args )
347 {
348     return s->pf_control( s, i_query, args );
349 }
350 static inline int stream_Control( stream_t *s, int i_query, ... )
351 {
352     va_list args;
353     int     i_result;
354
355     va_start( args, i_query );
356     i_result = s->pf_control( s, i_query, args );
357     va_end( args );
358     return i_result;
359 }
360 static inline int64_t stream_Tell( stream_t *s )
361 {
362     int64_t i_pos;
363     stream_Control( s, STREAM_GET_POSITION, &i_pos );
364     return i_pos;
365 }
366 static inline int64_t stream_Size( stream_t *s )
367 {
368     int64_t i_pos;
369     stream_Control( s, STREAM_GET_SIZE, &i_pos );
370     return i_pos;
371 }
372 static inline int stream_MTU( stream_t *s )
373 {
374     int i_mtu;
375     stream_Control( s, STREAM_GET_MTU, &i_mtu );
376     return i_mtu;
377 }
378 static inline int stream_Seek( stream_t *s, int64_t i_pos )
379 {
380     return stream_Control( s, STREAM_SET_POSITION, i_pos );
381 }
382
383 /**
384  * Read "i_size" bytes and store them in a block_t. If less than "i_size"
385  * bytes are available then return what is left and if nothing is availble,
386  * return NULL.
387  */
388 static inline block_t *stream_Block( stream_t *s, int i_size )
389 {
390     if( i_size <= 0 ) return NULL;
391
392     if( s->pf_block )
393     {
394         return s->pf_block( s, i_size );
395     }
396     else
397     {
398         /* emulate block read */
399         block_t *p_bk = block_New( s, i_size );
400         if( p_bk )
401         {
402             p_bk->i_buffer = stream_Read( s, p_bk->p_buffer, i_size );
403             if( p_bk->i_buffer > 0 )
404             {
405                 return p_bk;
406             }
407         }
408         if( p_bk ) block_Release( p_bk );
409         return NULL;
410     }
411 }
412
413 VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
414
415 /**
416  * Create a special stream and a demuxer, this allows chaining demuxers
417  */
418 #define stream_DemuxNew( a, b, c ) __stream_DemuxNew( VLC_OBJECT(a), b, c)
419 VLC_EXPORT( stream_t *,__stream_DemuxNew, ( vlc_object_t *p_obj, char *psz_demux, es_out_t *out ) );
420 VLC_EXPORT( void,      stream_DemuxSend,  ( stream_t *s, block_t *p_block ) );
421 VLC_EXPORT( void,      stream_DemuxDelete,( stream_t *s ) );
422
423 /**
424  * @}
425  */
426
427 /**
428  * \defgroup demux Demux
429  * @{
430  */
431
432 struct demux_t
433 {
434     VLC_COMMON_MEMBERS
435
436     /* Module properties */
437     module_t    *p_module;
438
439     /* eg informative but needed (we can have access+demux) */
440     char        *psz_access;
441     char        *psz_demux;
442     char        *psz_path;
443
444     /* input stream */
445     stream_t    *s;     /* NULL in case of a access+demux in one */
446
447     /* es output */
448     es_out_t    *out;   /* ou p_es_out */
449
450     /* set by demuxer */
451     int (*pf_demux)  ( demux_t * );   /* demux one frame only */
452     int (*pf_control)( demux_t *, int i_query, va_list args);
453
454     /* Demux has to maintain them uptodate
455      * when it is responsible of seekpoint/title*/
456     struct
457     {
458         unsigned int i_update;  /* Demux sets them on change,
459                                    Input removes them once take into account*/
460         /* Seekpoint/Title at demux level */
461         int          i_title;       /* idem, start from 0 (could be menu) */
462         int          i_seekpoint;   /* idem, start from 0 */
463     } info;
464     demux_sys_t *p_sys;
465 };
466
467 enum demux_query_e
468 {
469     DEMUX_GET_POSITION,         /* arg1= double *       res=    */
470     DEMUX_SET_POSITION,         /* arg1= double         res=can fail    */
471
472     DEMUX_GET_LENGTH,           /* arg1= int64_t *      res=    */
473     DEMUX_GET_TIME,             /* arg1= int64_t *      res=    */
474     DEMUX_SET_TIME,             /* arg1= int64_t        res=can fail    */
475
476     DEMUX_GET_FPS,              /* arg1= float *        res=can fail    */
477     DEMUX_GET_META,             /* arg1= vlc_meta_t **  res=can fail    */
478
479     DEMUX_GET_TITLE_INFO,       /* arg1=input_title_t*** arg2=int* can fail */
480     DEMUX_GET_SEEKPOINT_INFO,   /* arg1=seekpoint_t ***  arg2=int* can fail */
481
482     DEMUX_SET_TITLE,            /* arg1= int            can fail */
483     DEMUX_SET_SEEKPOINT,        /* arg1= int            can fail */
484 };
485
486 /* Demux */
487 VLC_EXPORT( int, demux_vaControl,        ( input_thread_t *, int i_query, va_list  ) );
488 VLC_EXPORT( int, demux_Control,          ( input_thread_t *, int i_query, ...  ) );
489
490 VLC_EXPORT( int, demux_vaControlDefault, ( input_thread_t *, int i_query, va_list  ) );
491
492 /* Access */
493 VLC_EXPORT( int, access_vaControl,       ( input_thread_t *, int i_query, va_list  ) );
494 VLC_EXPORT( int, access_Control,         ( input_thread_t *, int i_query, ...  ) );
495 VLC_EXPORT( int, access_vaControlDefault,( input_thread_t *, int i_query, va_list  ) );
496
497
498 /* stream_t *s could be null and then it mean a access+demux in one */
499 #define demux2_New( a, b, c, d ) __demux2_New(VLC_OBJECT(a), b, c, d)
500 VLC_EXPORT( demux_t *, __demux2_New,  ( vlc_object_t *p_obj, char *psz_mrl, stream_t *s, es_out_t *out ) );
501 VLC_EXPORT( void,      demux2_Delete, ( demux_t * ) );
502 VLC_EXPORT( int,       demux2_vaControlHelper, ( stream_t *, int64_t i_start, int64_t i_end, int i_bitrate, int i_align, int i_query, va_list args ) );
503
504 static inline int demux2_Demux( demux_t *p_demux )
505 {
506     return p_demux->pf_demux( p_demux );
507 }
508 static inline int demux2_vaControl( demux_t *p_demux, int i_query, va_list args )
509 {
510     return p_demux->pf_control( p_demux, i_query, args );
511 }
512 static inline int demux2_Control( demux_t *p_demux, int i_query, ... )
513 {
514     va_list args;
515     int     i_result;
516
517     va_start( args, i_query );
518     i_result = demux2_vaControl( p_demux, i_query, args );
519     va_end( args );
520     return i_result;
521 }
522
523 /* Subtitles */
524 VLC_EXPORT( char **, subtitles_Detect, ( input_thread_t *, char* path, char *fname ) );
525
526 /**
527  * @}
528  */
529
530
531 /**
532  * \defgroup input Input
533  * @{
534  */
535 enum input_query_e
536 {
537     INPUT_GET_POSITION,         /* arg1= double *       res=    */
538     INPUT_SET_POSITION,         /* arg1= double         res=can fail    */
539
540     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
541     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
542
543     INPUT_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
544
545     INPUT_GET_FPS,              /* arg1= float *        res=can fail    */
546     INPUT_GET_META,             /* arg1= vlc_meta_t **  res=can fail    */
547
548     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
549     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
550     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
551     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
552     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
553
554     INPUT_ADD_OPTION, /* arg1= char * arg2= char *  res=can fail    */
555
556     INPUT_ADD_INFO,   /* arg1= char * arg2= char * arg3=...  res=can fail    */
557     INPUT_GET_INFO,   /* arg1= char * arg2= char * arg3= char ** res=can fail*/
558
559     INPUT_SET_NAME,   /* arg1= char * res=can fail    */
560
561     INPUT_GET_SUBDELAY,    /* arg1 = int* res=can fail */
562     INPUT_SET_SUBDELAY,    /* arg1 = int  res=can fail */
563
564     INPUT_GET_DIVISIONS
565 };
566
567 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
568 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
569
570 /**
571  * @}
572  */
573
574 #endif