vlc_demux.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_demux.h: Demuxer descriptor, queries and methods
00003  *****************************************************************************
00004  * Copyright (C) 1999-2005 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_DEMUX_H
00025 #define VLC_DEMUX_H 1
00026 
00027 #include <vlc_es.h>
00028 #include <vlc_stream.h>
00029 #include <vlc_es_out.h>
00030 
00031 /**
00032  * \defgroup demux Demux
00033  * @{
00034  */
00035 
00036 struct demux_t
00037 {
00038     VLC_COMMON_MEMBERS
00039 
00040     /* Module properties */
00041     module_t    *p_module;
00042 
00043     /* eg informative but needed (we can have access+demux) */
00044     char        *psz_access;
00045     char        *psz_demux;
00046     char        *psz_path;
00047 
00048     /* input stream */
00049     stream_t    *s;     /* NULL in case of a access+demux in one */
00050 
00051     /* es output */
00052     es_out_t    *out;   /* our p_es_out */
00053 
00054     /* set by demuxer */
00055     int (*pf_demux)  ( demux_t * );   /* demux one frame only */
00056     int (*pf_control)( demux_t *, int i_query, va_list args);
00057 
00058     /* Demux has to maintain them uptodate
00059      * when it is responsible of seekpoint/title */
00060     struct
00061     {
00062         unsigned int i_update;  /* Demux sets them on change,
00063                                    Input removes them once take into account*/
00064         /* Seekpoint/Title at demux level */
00065         int          i_title;       /* idem, start from 0 (could be menu) */
00066         int          i_seekpoint;   /* idem, start from 0 */
00067     } info;
00068     demux_sys_t *p_sys;
00069 };
00070 
00071 
00072 /* demux_meta_t is returned by "meta reader" module to the demuxer */
00073 struct demux_meta_t
00074 {
00075     vlc_meta_t *p_meta;                 /**< meta data */
00076 
00077     int i_attachments;                  /**< number of attachments */
00078     input_attachment_t **attachments;    /**< array of attachments */
00079 };
00080 
00081 enum demux_query_e
00082 {
00083     /* I. Common queries to access_demux and demux */
00084     /* POSITION double between 0.0 and 1.0 */
00085     DEMUX_GET_POSITION,         /* arg1= double *       res=    */
00086     DEMUX_SET_POSITION,         /* arg1= double         res=can fail    */
00087 
00088     /* LENGTH/TIME in microsecond, 0 if unknown */
00089     DEMUX_GET_LENGTH,           /* arg1= int64_t *      res=    */
00090     DEMUX_GET_TIME,             /* arg1= int64_t *      res=    */
00091     DEMUX_SET_TIME,             /* arg1= int64_t        res=can fail    */
00092 
00093     /* TITLE_INFO only if more than 1 title or 1 chapter */
00094     DEMUX_GET_TITLE_INFO,       /* arg1=input_title_t*** arg2=int*
00095                                    arg3=int*pi_title_offset(0), arg4=int*pi_seekpoint_offset(0) can fail */
00096     /* TITLE/SEEKPOINT, only when TITLE_INFO succeed */
00097     DEMUX_SET_TITLE,            /* arg1= int            can fail */
00098     DEMUX_SET_SEEKPOINT,        /* arg1= int            can fail */
00099 
00100     /* DEMUX_SET_GROUP only a hit for demuxer (mainly DVB) to allow not
00101      * reading everything (you should not use this to call es_out_Control)
00102      * if you don't know what to do with it, just IGNORE it, it is safe(r)
00103      * -1 means all group, 0 default group (first es added) */
00104     DEMUX_SET_GROUP,            /* arg1= int            can fail */
00105 
00106     /* Ask the demux to demux until the given date at the next pf_demux call
00107      * but not more (and not less, at the precision available of course).
00108      * XXX: not mandatory (except for subtitle demux) but I will help a lot
00109      * for multi-input
00110      */
00111     DEMUX_SET_NEXT_DEMUX_TIME,  /* arg1= int64_t *      can fail */
00112     /* FPS for correct subtitles handling */
00113     DEMUX_GET_FPS,              /* arg1= double *       res=can fail    */
00114 
00115     /* Meta data */
00116     DEMUX_GET_META,             /* arg1= vlc_meta_t **  res=can fail    */
00117     DEMUX_HAS_UNSUPPORTED_META, /* arg1= bool *   res can fail    */
00118 
00119     /* Attachments */
00120     DEMUX_GET_ATTACHMENTS,      /* arg1=input_attachment_t***, int* res=can fail */
00121 
00122     /* II. Specific access_demux queries */
00123     DEMUX_CAN_PAUSE,            /* arg1= bool*    can fail (assume false)*/
00124     DEMUX_SET_PAUSE_STATE,      /* arg1= bool     can fail */
00125 
00126     DEMUX_GET_PTS_DELAY,        /* arg1= int64_t*       cannot fail */
00127 
00128     /* DEMUX_CAN_CONTROL_PACE returns true (*pb_pace) if we can read the
00129      * data at our pace */
00130     DEMUX_CAN_CONTROL_PACE,     /* arg1= bool*pb_pace    can fail (assume false) */
00131 
00132     /* DEMUX_CAN_CONTROL_RATE is called only if DEMUX_CAN_CONTROL_PACE has returned false.
00133      * *pb_rate should be true when the rate can be changed (using DEMUX_SET_RATE)
00134      * *pb_ts_rescale should be true when the timestamps (pts/dts/pcr) have to be rescaled */
00135     DEMUX_CAN_CONTROL_RATE,     /* arg1= bool*pb_rate arg2= bool*pb_ts_rescale  can fail(assume false) */
00136     /* DEMUX_SET_RATE is called only if DEMUX_CAN_CONTROL_RATE has returned true.
00137      * It should return the value really used in *pi_rate */
00138     DEMUX_SET_RATE,             /* arg1= int*pi_rate                                        can fail */
00139 
00140     DEMUX_CAN_SEEK,            /* arg1= bool*    can fail (assume false)*/
00141 };
00142 
00143 VLC_EXPORT( int,       demux_vaControlHelper, ( stream_t *, int64_t i_start, int64_t i_end, int i_bitrate, int i_align, int i_query, va_list args ) );
00144 
00145 /*************************************************************************
00146  * Miscellaneous helpers for demuxers
00147  *************************************************************************/
00148 
00149 static inline bool demux_IsPathExtension( demux_t *p_demux, const char *psz_extension )
00150 {
00151     const char *psz_ext = strrchr ( p_demux->psz_path, '.' );
00152     if( !psz_ext || strcasecmp( psz_ext, psz_extension ) )
00153         return false;
00154     return true;
00155 }
00156 
00157 static inline bool demux_IsForced( demux_t *p_demux, const char *psz_name )
00158 {
00159    if( !p_demux->psz_demux || strcmp( p_demux->psz_demux, psz_name ) )
00160         return false;
00161     return true;
00162 }
00163 
00164 #define DEMUX_INIT_COMMON() do {            \
00165     p_demux->pf_control = Control;          \
00166     p_demux->pf_demux = Demux;              \
00167     MALLOC_ERR( p_demux->p_sys, demux_sys_t ); \
00168     memset( p_demux->p_sys, 0, sizeof( demux_sys_t ) ); } while(0)
00169 
00170 #define STANDARD_DEMUX_INIT_MSG( msg ) do { \
00171     DEMUX_INIT_COMMON();                    \
00172     msg_Dbg( p_demux, msg ); } while(0)
00173 
00174 #define DEMUX_BY_EXTENSION( ext ) \
00175     demux_t *p_demux = (demux_t *)p_this; \
00176     if( !demux_IsPathExtension( p_demux, ext ) ) \
00177         return VLC_EGENERIC; \
00178     DEMUX_INIT_COMMON();
00179 
00180 #define DEMUX_BY_EXTENSION_MSG( ext, msg ) \
00181     demux_t *p_demux = (demux_t *)p_this; \
00182     if( !demux_IsPathExtension( p_demux, ext ) ) \
00183         return VLC_EGENERIC; \
00184     STANDARD_DEMUX_INIT_MSG( msg );
00185 
00186 #define DEMUX_BY_EXTENSION_OR_FORCED( ext, module ) \
00187     demux_t *p_demux = (demux_t *)p_this; \
00188     if( !demux_IsPathExtension( p_demux, ext ) && !demux_IsForced( p_demux, module ) ) \
00189         return VLC_EGENERIC; \
00190     DEMUX_INIT_COMMON();
00191 
00192 #define DEMUX_BY_EXTENSION_OR_FORCED_MSG( ext, module, msg ) \
00193     demux_t *p_demux = (demux_t *)p_this; \
00194     if( !demux_IsPathExtension( p_demux, ext ) && !demux_IsForced( p_demux, module ) ) \
00195         return VLC_EGENERIC; \
00196     STANDARD_DEMUX_INIT_MSG( msg );
00197 
00198 #define CHECK_PEEK( zepeek, size ) \
00199     if( stream_Peek( p_demux->s , &zepeek, size ) < size ){ \
00200         msg_Dbg( p_demux, "not enough data" ); return VLC_EGENERIC; }
00201 
00202 #define CHECK_PEEK_GOTO( zepeek, size ) \
00203     if( stream_Peek( p_demux->s , &zepeek, size ) < size ) { \
00204         msg_Dbg( p_demux, "not enough data" ); goto error; }
00205 
00206 #define POKE( peek, stuff, size ) (strncasecmp( (const char *)peek, stuff, size )==0)
00207 
00208 #define COMMON_INIT_PACKETIZER( location ) \
00209     location = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER ); \
00210     location->pf_decode_audio = 0; \
00211     location->pf_decode_video = 0; \
00212     location->pf_decode_sub = 0; \
00213     location->pf_packetize = 0; \
00214 
00215 #define INIT_APACKETIZER( location, a,b,c,d ) \
00216     COMMON_INIT_PACKETIZER(location ); \
00217     es_format_Init( &location->fmt_in, AUDIO_ES, \
00218                     VLC_FOURCC( a, b, c, d ) );
00219 
00220 #define INIT_VPACKETIZER( location, a,b,c,d ) \
00221     COMMON_INIT_PACKETIZER(location ); \
00222     es_format_Init( &location->fmt_in, VIDEO_ES, \
00223                     VLC_FOURCC( a, b, c, d ) );
00224 
00225 /* BEWARE ! This can lead to memory leaks ! */
00226 #define LOAD_PACKETIZER_OR_FAIL( location, msg ) \
00227     location->p_module = \
00228         module_Need( location, "packetizer", NULL, 0 ); \
00229     if( location->p_module == NULL ) \
00230     { \
00231         vlc_object_release( location ); \
00232         msg_Err( p_demux, "cannot find packetizer for " # msg ); \
00233         free( p_sys ); \
00234         return VLC_EGENERIC; \
00235     }
00236 
00237 #define DESTROY_PACKETIZER( location ) \
00238     if( location->p_module ) module_Unneed( location, location->p_module ); \
00239     vlc_object_release( location );
00240 
00241 /**
00242  * @}
00243  */
00244 
00245 #endif

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1