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;
66 vlc_bool_t b_menu; /* Is it a menu or a normal entry */
68 int64_t i_length; /* Length(microsecond) if known, else 0 */
69 int64_t i_size; /* Size (bytes) if known, else 0 */
73 seekpoint_t **seekpoint;
77 static inline input_title_t *vlc_input_title_New( )
79 input_title_t *t = (input_title_t*)malloc( sizeof( input_title_t ) );
82 t->b_menu = VLC_FALSE;
90 static inline void vlc_input_title_Delete( input_title_t *t )
96 if( t->psz_name ) free( t->psz_name );
97 for( i = 0; i < t->i_seekpoint; i++ )
99 if( t->seekpoint[i]->psz_name ) free( t->seekpoint[i]->psz_name );
100 free( t->seekpoint[i] );
102 if( t->seekpoint ) free( t->seekpoint );
106 static inline input_title_t *vlc_input_title_Duplicate( input_title_t *t )
108 input_title_t *dup = vlc_input_title_New( );
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 )
118 dup->seekpoint = (seekpoint_t**)calloc( t->i_seekpoint,
119 sizeof(seekpoint_t*) );
121 for( i = 0; i < t->i_seekpoint; i++ )
123 dup->seekpoint[i] = vlc_seekpoint_Duplicate( t->seekpoint[i] );
131 * \defgroup es out Es Out
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 */
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* */
150 ES_OUT_SET_MODE, /* arg1= int */
151 ES_OUT_GET_MODE, /* arg2= int* */
153 /* set es selected for the es category(audio/video/spu) */
154 ES_OUT_SET_ES, /* arg1= es_out_id_t* */
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* */
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 */
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 );
176 static inline es_out_id_t * es_out_Add( es_out_t *out, es_format_t *fmt )
178 return out->pf_add( out, fmt );
180 static inline void es_out_Del( es_out_t *out, es_out_id_t *id )
182 out->pf_del( out, id );
184 static inline int es_out_Send( es_out_t *out, es_out_id_t *id,
187 return out->pf_send( out, id, p_block );
190 static inline int es_out_vaControl( es_out_t *out, int i_query, va_list args )
192 return out->pf_control( out, i_query, args );
194 static inline int es_out_Control( es_out_t *out, int i_query, ... )
199 va_start( args, i_query );
200 i_result = es_out_vaControl( out, i_query, args );
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
216 * \defgroup access Access
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 */
229 ACCESS_GET_MTU, /* arg1= int* cannot fail(0 if no sense)*/
230 ACCESS_GET_PTS_DELAY, /* arg1= int64_t* cannot fail */
232 ACCESS_GET_TITLE_INFO, /* arg1=input_title_t*** arg2=int* can fail */
235 ACCESS_SET_PAUSE_STATE, /* arg1= vlc_bool_t can fail */
238 ACCESS_SET_TITLE, /* arg1= int can fail */
239 ACCESS_SET_SEEKPOINT, /* arg1= int can fail */
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 */
250 /* Module properties */
253 /* Access name (empty if non forced) */
255 /* Access path/url/filename/.... */
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 */
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 */
268 /* Called for each seek.
270 int (*pf_seek) ( access_t *, int64_t ); /* can be null if can't seek */
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);
276 /* Access has to maintain them uptodate */
279 unsigned int i_update; /* Access sets them on change,
280 Input removes them once take into account*/
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 */
286 int i_title; /* idem, start from 0 (could be menu) */
287 int i_seekpoint;/* idem, start from 0 */
292 #define access2_New( a, b, c, d ) __access2_New(VLC_OBJECT(a), b, c, d )
293 VLC_EXPORT( access_t *, __access2_New, ( vlc_object_t *p_obj, char *psz_access, char *psz_demux, char *psz_path ) );
294 VLC_EXPORT( void, access2_Delete, ( access_t * ) );
296 static inline int access2_vaControl( access_t *p_access, int i_query, va_list args )
298 return p_access->pf_control( p_access, i_query, args );
300 static inline int access2_Control( access_t *p_access, int i_query, ... )
305 va_start( args, i_query );
306 i_result = access2_vaControl( p_access, i_query, args );
316 * \defgroup stream Stream
318 * This will allow you to easily handle read/seek in demuxer modules.
323 * Possible commands to send to stream_Control() and stream_vaControl()
328 STREAM_CAN_SEEK, /**< arg1= vlc_bool_t * res=cannot fail*/
329 STREAM_CAN_FASTSEEK, /**< arg1= vlc_bool_t * res=cannot fail*/
332 STREAM_SET_POSITION, /**< arg1= int64_t res=can fail */
333 STREAM_GET_POSITION, /**< arg1= int64_t * res=cannot fail*/
335 STREAM_GET_SIZE, /**< arg1= int64_t * res=cannot fail (0 if no sense)*/
337 STREAM_GET_MTU, /**< arg1= int * res=cannot fail (0 if no sense)*/
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 */
346 * stream_t definition
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 );
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.
366 static inline int stream_Read( stream_t *s, void *p_read, int i_read )
368 return s->pf_read( s, p_read, i_read );
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)
381 static inline int stream_Peek( stream_t *s, uint8_t **pp_peek, int i_peek )
383 return s->pf_peek( s, pp_peek, i_peek );
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
391 static inline int stream_vaControl( stream_t *s, int i_query, va_list args )
393 return s->pf_control( s, i_query, args );
395 static inline int stream_Control( stream_t *s, int i_query, ... )
400 va_start( args, i_query );
401 i_result = s->pf_control( s, i_query, args );
405 static inline int64_t stream_Tell( stream_t *s )
408 stream_Control( s, STREAM_GET_POSITION, &i_pos );
411 static inline int64_t stream_Size( stream_t *s )
414 stream_Control( s, STREAM_GET_SIZE, &i_pos );
417 static inline int stream_MTU( stream_t *s )
420 stream_Control( s, STREAM_GET_MTU, &i_mtu );
423 static inline int stream_Seek( stream_t *s, int64_t i_pos )
425 return stream_Control( s, STREAM_SET_POSITION, i_pos );
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,
433 static inline block_t *stream_Block( stream_t *s, int i_size )
435 if( i_size <= 0 ) return NULL;
439 return s->pf_block( s, i_size );
443 /* emulate block read */
444 block_t *p_bk = block_New( s, i_size );
447 p_bk->i_buffer = stream_Read( s, p_bk->p_buffer, i_size );
448 if( p_bk->i_buffer > 0 )
453 if( p_bk ) block_Release( p_bk );
458 VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
461 * Create a special stream and a demuxer, this allows chaining demuxers
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 ) );
473 * \defgroup demux Demux
481 /* Module properties */
484 /* eg informative but needed (we can have access+demux) */
490 stream_t *s; /* NULL in case of a access+demux in one */
493 es_out_t *out; /* ou p_es_out */
496 int (*pf_demux) ( demux_t * ); /* demux one frame only */
497 int (*pf_control)( demux_t *, int i_query, va_list args);
499 /* Demux has to maintain them uptodate
500 * when it is responsible of seekpoint/title
501 * XXX: don't use them yet */
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 */
515 DEMUX_GET_POSITION, /* arg1= double * res= */
516 DEMUX_SET_POSITION, /* arg1= double res=can fail */
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 */
522 DEMUX_GET_FPS, /* arg1= float * res=can fail */
523 DEMUX_GET_META, /* arg1= vlc_meta_t ** res=can fail */
525 DEMUX_GET_TITLE_INFO, /* arg1=input_title_t*** arg2=int* can fail */
527 DEMUX_SET_TITLE, /* arg1= int can fail */
528 DEMUX_SET_SEEKPOINT, /* arg1= int can fail */
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, ... ) );
535 VLC_EXPORT( int, demux_vaControlDefault, ( input_thread_t *, int i_query, va_list ) );
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 ) );
543 /* stream_t *s could be null and then it mean a access+demux in one */
544 #define demux2_New( a, b, c, d, e, f ) __demux2_New(VLC_OBJECT(a),b,c,d,e,f)
545 VLC_EXPORT( demux_t *, __demux2_New, ( vlc_object_t *p_obj, char *psz_access, char *psz_demux, char *psz_path, 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 ) );
549 static inline int demux2_Demux( demux_t *p_demux )
551 return p_demux->pf_demux( p_demux );
553 static inline int demux2_vaControl( demux_t *p_demux, int i_query, va_list args )
555 return p_demux->pf_control( p_demux, i_query, args );
557 static inline int demux2_Control( demux_t *p_demux, int i_query, ... )
562 va_start( args, i_query );
563 i_result = demux2_vaControl( p_demux, i_query, args );
569 VLC_EXPORT( char **, subtitles_Detect, ( input_thread_t *, char* path, char *fname ) );
577 * \defgroup input Input
582 /* input variable "position" */
583 INPUT_GET_POSITION, /* arg1= double * res= */
584 INPUT_SET_POSITION, /* arg1= double res=can fail */
586 /* input variable "length" */
587 INPUT_GET_LENGTH, /* arg1= int64_t * res=can fail */
589 /* input variable "time" */
590 INPUT_GET_TIME, /* arg1= int64_t * res= */
591 INPUT_SET_TIME, /* arg1= int64_t res=can fail */
593 /* input variable "rate" (1 is DEFAULT_RATE) */
594 INPUT_GET_RATE, /* arg1= int * res= */
595 INPUT_SET_RATE, /* arg1= int res=can fail */
597 /* input variable "state" */
598 INPUT_GET_STATE, /* arg1= int * res= */
599 INPUT_SET_STATE, /* arg1= int res=can fail */
603 INPUT_GET_BOOKMARKS, /* arg1= seekpoint_t *** arg2= int * res=can fail */
604 INPUT_CLEAR_BOOKMARKS, /* res=can fail */
605 INPUT_ADD_BOOKMARK, /* arg1= seekpoint_t * res=can fail */
606 INPUT_CHANGE_BOOKMARK, /* arg1= seekpoint_t * arg2= int * res=can fail */
607 INPUT_DEL_BOOKMARK, /* arg1= seekpoint_t * res=can fail */
608 INPUT_SET_BOOKMARK, /* arg1= int res=can fail */
610 INPUT_ADD_OPTION, /* arg1= char * arg2= char * res=can fail */
613 INPUT_ADD_INFO, /* arg1= char * arg2= char * arg3=... res=can fail */
614 INPUT_GET_INFO, /* arg1= char * arg2= char * arg3= char ** res=can fail*/
616 INPUT_SET_NAME, /* arg1= char * res=can fail */
619 INPUT_GET_SUBDELAY, /* arg1 = int* res=can fail */
620 INPUT_SET_SUBDELAY, /* arg1 = int res=can fail */
623 VLC_EXPORT( int, input_vaControl,( input_thread_t *, int i_query, va_list ) );
624 VLC_EXPORT( int, input_Control, ( input_thread_t *, int i_query, ... ) );