]> git.sesse.net Git - vlc/blob - include/ninput.h
0b2f2737a9e65445a2bf77432b0bdcf2e0321a6a
[vlc] / include / ninput.h
1 /*****************************************************************************
2  * ninput.h
3  *****************************************************************************
4  * Copyright (C) 1999-2001 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 enum es_out_mode_e
30 {
31     ES_OUT_MODE_NONE,   /* don't select anything */
32     ES_OUT_MODE_ALL,    /* eg for stream output */
33     ES_OUT_MODE_AUTO    /* best audio/video or for input follow audio-channel, spu-channel */
34 };
35
36 enum es_out_query_e
37 {
38     /* activate apply of mode */
39     ES_OUT_SET_ACTIVE,  /* arg1= vlc_bool_t                     */
40     /* see if mode is currently aplied or not */
41     ES_OUT_GET_ACTIVE,  /* arg1= vlc_bool_t*                    */
42
43     /* set/get mode */
44     ES_OUT_SET_MODE,    /* arg1= int                            */
45     ES_OUT_GET_MODE,    /* arg2= int*                           */
46
47     /* set es selected for the es category(audio/video/spu) */
48     ES_OUT_SET_ES,      /* arg1= es_out_id_t*                   */
49
50     /* force selection/unselection of the ES (bypass current mode)*/
51     ES_OUT_SET_ES_STATE,/* arg1= es_out_id_t* arg2=vlc_bool_t   */
52     ES_OUT_GET_ES_STATE,/* arg1= es_out_id_t* arg2=vlc_bool_t*  */
53
54     /* XXX XXX XXX Don't use them YET !!! */
55     ES_OUT_SET_PCR,             /* arg1=int64_t i_pcr(microsecond!) (using default group 0)*/
56     ES_OUT_SET_GROUP_PCR,       /* arg1= int i_group, arg2=int64_t i_pcr(microsecond!)*/
57     ES_OUT_RESET_PCR    /* no arg */
58 };
59
60 struct es_out_t
61 {
62     es_out_id_t *(*pf_add)    ( es_out_t *, es_format_t * );
63     int          (*pf_send)   ( es_out_t *, es_out_id_t *, block_t * );
64     void         (*pf_del)    ( es_out_t *, es_out_id_t * );
65     int          (*pf_control)( es_out_t *, int i_query, va_list );
66
67     es_out_sys_t    *p_sys;
68 };
69
70 static inline es_out_id_t * es_out_Add( es_out_t *out, es_format_t *fmt )
71 {
72     return out->pf_add( out, fmt );
73 }
74 static inline void es_out_Del( es_out_t *out, es_out_id_t *id )
75 {
76     out->pf_del( out, id );
77 }
78 static inline int es_out_Send( es_out_t *out, es_out_id_t *id,
79                                block_t *p_block )
80 {
81     return out->pf_send( out, id, p_block );
82 }
83
84 static inline int es_out_vaControl( es_out_t *out, int i_query, va_list args )
85 {
86     return out->pf_control( out, i_query, args );
87 }
88 static inline int es_out_Control( es_out_t *out, int i_query, ... )
89 {
90     va_list args;
91     int     i_result;
92
93     va_start( args, i_query );
94     i_result = es_out_vaControl( out, i_query, args );
95     va_end( args );
96     return i_result;
97 }
98
99 /**
100  * \defgroup stream Stream
101  *
102  *  This will allow you to easily handle read/seek in demuxer modules.
103  * @{
104  */
105
106 /**
107  * Possible commands to send to stream_Control() and stream_vaControl()
108  */
109 enum stream_query_e
110 {
111     /* capabilities */
112     STREAM_CAN_SEEK,            /**< arg1= vlc_bool_t *   res=cannot fail*/
113     STREAM_CAN_FASTSEEK,        /**< arg1= vlc_bool_t *   res=cannot fail*/
114
115     /* */
116     STREAM_SET_POSITION,        /**< arg1= int64_t        res=can fail  */
117     STREAM_GET_POSITION,        /**< arg1= int64_t *      res=cannot fail*/
118
119     STREAM_GET_SIZE,            /**< arg1= int64_t *      res=cannot fail (0 if no sense)*/
120
121     STREAM_GET_MTU              /**< arg1= int *          res=cannot fail (0 if no sense)*/
122 };
123
124 /**
125  * stream_t definition
126  */
127 struct stream_t
128 {
129     VLC_COMMON_MEMBERS
130
131     block_t *(*pf_block)  ( stream_t *, int i_size );
132     int      (*pf_read)   ( stream_t *, void *p_read, int i_read );
133     int      (*pf_peek)   ( stream_t *, uint8_t **pp_peek, int i_peek );
134     int      (*pf_control)( stream_t *, int i_query, va_list );
135
136     stream_sys_t *p_sys;
137 };
138
139 /**
140  * Try to read "i_read" bytes into a buffer pointed by "p_read".  If
141  * "p_read" is NULL then data are skipped instead of read.  The return
142  * value is the real numbers of bytes read/skip. If this value is less
143  * than i_read that means that it's the end of the stream.
144  */
145 static inline int stream_Read( stream_t *s, void *p_read, int i_read )
146 {
147     return s->pf_read( s, p_read, i_read );
148 }
149
150 /**
151  * Store in pp_peek a pointer to the next "i_peek" bytes in the stream
152  * \return The real numbers of valid bytes, if it's less
153  * or equal to 0, *pp_peek is invalid.
154  * \note pp_peek is a pointer to internal buffer and it will be invalid as
155  * soons as other stream_* functions are called.
156  * \note Due to input limitation, it could be less than i_peek without meaning
157  * the end of the stream (but only when you have i_peek >=
158  * p_input->i_bufsize)
159  */
160 static inline int stream_Peek( stream_t *s, uint8_t **pp_peek, int i_peek )
161 {
162     return s->pf_peek( s, pp_peek, i_peek );
163 }
164
165 /**
166  * Use to control the "stream_t *". Look at #stream_query_e for
167  * possible "i_query" value and format arguments.  Return VLC_SUCCESS
168  * if ... succeed ;) and VLC_EGENERIC if failed or unimplemented
169  */
170 static inline int stream_vaControl( stream_t *s, int i_query, va_list args )
171 {
172     return s->pf_control( s, i_query, args );
173 }
174 static inline int stream_Control( stream_t *s, int i_query, ... )
175 {
176     va_list args;
177     int     i_result;
178
179     va_start( args, i_query );
180     i_result = s->pf_control( s, i_query, args );
181     va_end( args );
182     return i_result;
183 }
184 static inline int64_t stream_Tell( stream_t *s )
185 {
186     int64_t i_pos;
187     stream_Control( s, STREAM_GET_POSITION, &i_pos );
188     return i_pos;
189 }
190 static inline int64_t stream_Size( stream_t *s )
191 {
192     int64_t i_pos;
193     stream_Control( s, STREAM_GET_SIZE, &i_pos );
194     return i_pos;
195 }
196 static inline int stream_MTU( stream_t *s )
197 {
198     int i_mtu;
199     stream_Control( s, STREAM_GET_MTU, &i_mtu );
200     return i_mtu;
201 }
202 static inline int stream_Seek( stream_t *s, int64_t i_pos )
203 {
204     return stream_Control( s, STREAM_SET_POSITION, i_pos );
205 }
206
207 /**
208  * Read "i_size" bytes and store them in a block_t. If less than "i_size"
209  * bytes are available then return what is left and if nothing is availble,
210  * return NULL.
211  */
212 static inline block_t *stream_Block( stream_t *s, int i_size )
213 {
214     if( i_size <= 0 ) return NULL;
215
216     if( s->pf_block )
217     {
218         return s->pf_block( s, i_size );
219     }
220     else
221     {
222         /* emulate block read */
223         block_t *p_bk = block_New( s, i_size );
224         if( p_bk )
225         {
226             p_bk->i_buffer = stream_Read( s, p_bk->p_buffer, i_size );
227             if( p_bk->i_buffer > 0 )
228             {
229                 return p_bk;
230             }
231         }
232         if( p_bk ) block_Release( p_bk );
233         return NULL;
234     }
235 }
236
237 VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
238
239 /**
240  * Create a special stream and a demuxer, this allows chaining demuxers
241  */
242 #define stream_DemuxNew( a, b, c ) __stream_DemuxNew( VLC_OBJECT(a), b, c)
243 VLC_EXPORT( stream_t *,__stream_DemuxNew, ( vlc_object_t *p_obj, char *psz_demux, es_out_t *out ) );
244 VLC_EXPORT( void,      stream_DemuxSend,  ( stream_t *s, block_t *p_block ) );
245 VLC_EXPORT( void,      stream_DemuxDelete,( stream_t *s ) );
246
247 /**
248  * @}
249  */
250
251 /**
252  * \defgroup demux Demux
253  * @{
254  */
255
256 struct demux_t
257 {
258     VLC_COMMON_MEMBERS
259
260     /* Module properties */
261     module_t    *p_module;
262
263     /* eg informative but needed (we can have access+demux) */
264     char        *psz_access;
265     char        *psz_demux;
266     char        *psz_path;
267
268     /* input stream */
269     stream_t    *s;     /* NULL in case of a access+demux in one */
270
271     /* es output */
272     es_out_t    *out;   /* ou p_es_out */
273
274     /* set by demuxer */
275     int (*pf_demux)  ( demux_t * );   /* demux one frame only */
276     int (*pf_control)( demux_t *, int i_query, va_list args);
277     demux_sys_t *p_sys;
278 };
279
280 enum demux_query_e
281 {
282     DEMUX_GET_POSITION,         /* arg1= double *       res=    */
283     DEMUX_SET_POSITION,         /* arg1= double         res=can fail    */
284
285     DEMUX_GET_TIME,             /* arg1= int64_t *      res=    */
286     DEMUX_SET_TIME,             /* arg1= int64_t        res=can fail    */
287
288     DEMUX_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
289
290     DEMUX_GET_FPS,              /* arg1= float *        res=can fail    */
291     DEMUX_GET_META              /* arg1= vlc_meta_t **  res=can fail    */
292 };
293
294 struct seekpoint_t
295 {
296     int64_t i_byte_offset;
297     int64_t i_time_offset;
298     char    *psz_name;
299 };
300
301 static inline seekpoint_t *vlc_seekpoint_New( void )
302 {
303     seekpoint_t *point = (seekpoint_t*)malloc( sizeof( seekpoint_t ) );
304     point->i_byte_offset = point->i_time_offset;
305     point->psz_name = NULL;
306     return point;
307 }
308
309 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
310 {
311     if( !point ) return;
312     if( point->psz_name ) free( point->psz_name );
313     free( point );
314 }
315
316 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
317 {
318     seekpoint_t *point = vlc_seekpoint_New();
319     if( src->psz_name ) point->psz_name = strdup( src->psz_name );
320     point->i_time_offset = src->i_time_offset;
321     point->i_byte_offset = src->i_byte_offset;
322     return point;
323 }
324
325 /* Demux */
326 VLC_EXPORT( int, demux_vaControl,        ( input_thread_t *, int i_query, va_list  ) );
327 VLC_EXPORT( int, demux_Control,          ( input_thread_t *, int i_query, ...  ) );
328
329 VLC_EXPORT( int, demux_vaControlDefault, ( input_thread_t *, int i_query, va_list  ) );
330
331
332 /* New demux arch: don't touch that */
333 /* stream_t *s could be null and then it mean a access+demux in one */
334 #define demux2_New( a, b, c, d ) __demux2_New(VLC_OBJECT(a), b, c, d)
335 VLC_EXPORT( demux_t *, __demux2_New,  ( vlc_object_t *p_obj, char *psz_mrl, stream_t *s, es_out_t *out ) );
336 VLC_EXPORT( void,      demux2_Delete, ( demux_t * ) );
337 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 ) );
338
339 static inline int demux2_Demux( demux_t *p_demux )
340 {
341     return p_demux->pf_demux( p_demux );
342 }
343 static inline int demux2_vaControl( demux_t *p_demux, int i_query, va_list args )
344 {
345     return p_demux->pf_control( p_demux, i_query, args );
346 }
347 static inline int demux2_Control( demux_t *p_demux, int i_query, ... )
348 {
349     va_list args;
350     int     i_result;
351
352     va_start( args, i_query );
353     i_result = demux2_vaControl( p_demux, i_query, args );
354     va_end( args );
355     return i_result;
356 }
357
358 /* Subtitles */
359 VLC_EXPORT( char **, subtitles_Detect, ( input_thread_t *, char* path, char *fname ) );
360
361 /**
362  * @}
363  */
364
365
366 /**
367  * \defgroup input Input
368  * @{
369  */
370 enum input_query_e
371 {
372     INPUT_GET_POSITION,         /* arg1= double *       res=    */
373     INPUT_SET_POSITION,         /* arg1= double         res=can fail    */
374
375     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
376     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
377
378     INPUT_GET_LENGTH,           /* arg1= int64_t *      res=can fail    */
379
380     INPUT_GET_FPS,              /* arg1= float *        res=can fail    */
381     INPUT_GET_META,             /* arg1= vlc_meta_t **  res=can fail    */
382
383     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
384     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
385     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
386     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
387     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
388
389     INPUT_GET_SUBDELAY,    /* arg1 = int* res=can fail */
390     INPUT_SET_SUBDELAY,    /* arg1 = int  res=can fail */
391
392     INPUT_GET_DIVISIONS
393 };
394
395 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list  ) );
396 VLC_EXPORT( int, input_Control,  ( input_thread_t *, int i_query, ...  ) );
397
398 /**
399  * @}
400  */
401
402 #endif