1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
32 int64_t i_byte_offset;
33 int64_t i_time_offset;
37 static inline seekpoint_t *vlc_seekpoint_New( void )
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;
46 static inline void vlc_seekpoint_Delete( seekpoint_t *point )
49 if( point->psz_name ) free( point->psz_name );
53 static inline seekpoint_t *vlc_seekpoint_Duplicate( seekpoint_t *src )
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;
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)*/
71 static inline input_title_t *vlc_input_title_New( )
73 input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
75 t->b_menu = VLC_FALSE;
82 static inline void vlc_input_title_Delete( input_title_t *t )
86 if( t->psz_name ) free( t->psz_name );
91 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
93 input_title_t *dup = vlc_input_title_New( );
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 );
104 * \defgroup es out Es Out
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 */
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* */
123 ES_OUT_SET_MODE, /* arg1= int */
124 ES_OUT_GET_MODE, /* arg2= int* */
126 /* set es selected for the es category(audio/video/spu) */
127 ES_OUT_SET_ES, /* arg1= es_out_id_t* */
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* */
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 */
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 );
149 static inline es_out_id_t * es_out_Add( es_out_t *out, es_format_t *fmt )
151 return out->pf_add( out, fmt );
153 static inline void es_out_Del( es_out_t *out, es_out_id_t *id )
155 out->pf_del( out, id );
157 static inline int es_out_Send( es_out_t *out, es_out_id_t *id,
160 return out->pf_send( out, id, p_block );
163 static inline int es_out_vaControl( es_out_t *out, int i_query, va_list args )
165 return out->pf_control( out, i_query, args );
167 static inline int es_out_Control( es_out_t *out, int i_query, ... )
172 va_start( args, i_query );
173 i_result = es_out_vaControl( out, i_query, args );
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
189 * \defgroup access Access
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 */
202 ACCESS_GET_MTU, /* arg1= int* cannot fail(0 if no sense)*/
203 ACCESS_GET_PTS_DELAY, /* arg1= int64_t* cannot fail */
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 */
209 ACCESS_SET_PAUSE_STATE, /* arg1= vlc_bool_t can fail */
212 ACCESS_SET_TITLE, /* arg1= int can fail */
213 ACCESS_SET_SEEKPOINT, /* arg1= int can fail */
220 /* Module properties */
223 /* Access name (empty if non forced) */
226 /* Access can fill this entry to force a demuxer */
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 */
234 int (*pf_control)( access_t *, int i_query, va_list args); /* mandatory */
236 /* access has to maintain them uptodate */
239 unsigned int i_update; /* Access sets them on change,
240 Input removes them once take into account*/
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 */
246 int i_title; /* idem, start from 0 (could be menu) */
247 int i_seekpoint;/* idem, start from 0 */
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 * ) );
256 static inline int access2_vaControl( access_t *p_access, int i_query, va_list args )
258 return p_access->pf_control( p_access, i_query, args );
260 static inline int access2_Control( access_t *p_access, int i_query, ... )
265 va_start( args, i_query );
266 i_result = access2_vaControl( p_access, i_query, args );
276 * \defgroup stream Stream
278 * This will allow you to easily handle read/seek in demuxer modules.
283 * Possible commands to send to stream_Control() and stream_vaControl()
288 STREAM_CAN_SEEK, /**< arg1= vlc_bool_t * res=cannot fail*/
289 STREAM_CAN_FASTSEEK, /**< arg1= vlc_bool_t * res=cannot fail*/
292 STREAM_SET_POSITION, /**< arg1= int64_t res=can fail */
293 STREAM_GET_POSITION, /**< arg1= int64_t * res=cannot fail*/
295 STREAM_GET_SIZE, /**< arg1= int64_t * res=cannot fail (0 if no sense)*/
297 STREAM_GET_MTU /**< arg1= int * res=cannot fail (0 if no sense)*/
301 * stream_t definition
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 );
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.
321 static inline int stream_Read( stream_t *s, void *p_read, int i_read )
323 return s->pf_read( s, p_read, i_read );
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)
336 static inline int stream_Peek( stream_t *s, uint8_t **pp_peek, int i_peek )
338 return s->pf_peek( s, pp_peek, i_peek );
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
346 static inline int stream_vaControl( stream_t *s, int i_query, va_list args )
348 return s->pf_control( s, i_query, args );
350 static inline int stream_Control( stream_t *s, int i_query, ... )
355 va_start( args, i_query );
356 i_result = s->pf_control( s, i_query, args );
360 static inline int64_t stream_Tell( stream_t *s )
363 stream_Control( s, STREAM_GET_POSITION, &i_pos );
366 static inline int64_t stream_Size( stream_t *s )
369 stream_Control( s, STREAM_GET_SIZE, &i_pos );
372 static inline int stream_MTU( stream_t *s )
375 stream_Control( s, STREAM_GET_MTU, &i_mtu );
378 static inline int stream_Seek( stream_t *s, int64_t i_pos )
380 return stream_Control( s, STREAM_SET_POSITION, i_pos );
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,
388 static inline block_t *stream_Block( stream_t *s, int i_size )
390 if( i_size <= 0 ) return NULL;
394 return s->pf_block( s, i_size );
398 /* emulate block read */
399 block_t *p_bk = block_New( s, i_size );
402 p_bk->i_buffer = stream_Read( s, p_bk->p_buffer, i_size );
403 if( p_bk->i_buffer > 0 )
408 if( p_bk ) block_Release( p_bk );
413 VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
416 * Create a special stream and a demuxer, this allows chaining demuxers
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 ) );
428 * \defgroup demux Demux
436 /* Module properties */
439 /* eg informative but needed (we can have access+demux) */
445 stream_t *s; /* NULL in case of a access+demux in one */
448 es_out_t *out; /* ou p_es_out */
451 int (*pf_demux) ( demux_t * ); /* demux one frame only */
452 int (*pf_control)( demux_t *, int i_query, va_list args);
454 /* Demux has to maintain them uptodate
455 * when it is responsible of seekpoint/title*/
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 */
469 DEMUX_GET_POSITION, /* arg1= double * res= */
470 DEMUX_SET_POSITION, /* arg1= double res=can fail */
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 */
476 DEMUX_GET_FPS, /* arg1= float * res=can fail */
477 DEMUX_GET_META, /* arg1= vlc_meta_t ** res=can fail */
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 */
482 DEMUX_SET_TITLE, /* arg1= int can fail */
483 DEMUX_SET_SEEKPOINT, /* arg1= int can fail */
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, ... ) );
490 VLC_EXPORT( int, demux_vaControlDefault, ( input_thread_t *, int i_query, va_list ) );
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 ) );
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 ) );
504 static inline int demux2_Demux( demux_t *p_demux )
506 return p_demux->pf_demux( p_demux );
508 static inline int demux2_vaControl( demux_t *p_demux, int i_query, va_list args )
510 return p_demux->pf_control( p_demux, i_query, args );
512 static inline int demux2_Control( demux_t *p_demux, int i_query, ... )
517 va_start( args, i_query );
518 i_result = demux2_vaControl( p_demux, i_query, args );
524 VLC_EXPORT( char **, subtitles_Detect, ( input_thread_t *, char* path, char *fname ) );
532 * \defgroup input Input
537 INPUT_GET_POSITION, /* arg1= double * res= */
538 INPUT_SET_POSITION, /* arg1= double res=can fail */
540 INPUT_GET_TIME, /* arg1= int64_t * res= */
541 INPUT_SET_TIME, /* arg1= int64_t res=can fail */
543 INPUT_GET_LENGTH, /* arg1= int64_t * res=can fail */
545 INPUT_GET_FPS, /* arg1= float * res=can fail */
546 INPUT_GET_META, /* arg1= vlc_meta_t ** res=can fail */
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 */
554 INPUT_ADD_OPTION, /* arg1= char * arg2= char * res=can fail */
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*/
559 INPUT_SET_NAME, /* arg1= char * res=can fail */
561 INPUT_GET_SUBDELAY, /* arg1 = int* res=can fail */
562 INPUT_SET_SUBDELAY, /* arg1 = int res=can fail */
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, ... ) );