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