vlc_access.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_access.h: Access descriptor, queries and methods
00003  *****************************************************************************
00004  * Copyright (C) 1999-2006 VLC authors and VideoLAN
00005  * $Id: df8cf1af98f0fe94a42fa9c402718d9a18bcfa7c $
00006  *
00007  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00008  *
00009  * This program is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_ACCESS_H
00025 #define VLC_ACCESS_H 1
00026 
00027 /**
00028  * \file
00029  * This file defines functions and definitions for access object
00030  */
00031 
00032 #include <vlc_block.h>
00033 
00034 /**
00035  * \defgroup access Access
00036  * @{
00037  */
00038 
00039 enum access_query_e
00040 {
00041     /* capabilities */
00042     ACCESS_CAN_SEEK,        /* arg1= bool*    cannot fail */
00043     ACCESS_CAN_FASTSEEK,    /* arg1= bool*    cannot fail */
00044     ACCESS_CAN_PAUSE,       /* arg1= bool*    cannot fail */
00045     ACCESS_CAN_CONTROL_PACE,/* arg1= bool*    cannot fail */
00046 
00047     /* */
00048     ACCESS_GET_PTS_DELAY = 0x101,/* arg1= int64_t*       cannot fail */
00049     /* */
00050     ACCESS_GET_TITLE_INFO,  /* arg1=input_title_t*** arg2=int*      res=can fail */
00051     /* Meta data */
00052     ACCESS_GET_META,        /* arg1= vlc_meta_t **                  res=can fail */
00053 
00054     /* */
00055     ACCESS_GET_CONTENT_TYPE,/* arg1=char **ppsz_content_type                       res=can fail */
00056 
00057     /* */
00058     ACCESS_GET_SIGNAL,      /* arg1=double *pf_quality, arg2=double *pf_strength   res=can fail */
00059 
00060     /* */
00061     ACCESS_SET_PAUSE_STATE = 0x200, /* arg1= bool           can fail */
00062 
00063     /* */
00064     ACCESS_SET_TITLE,       /* arg1= int            can fail */
00065     ACCESS_SET_SEEKPOINT,   /* arg1= int            can fail */
00066 
00067     /* Special mode for access/demux communication
00068      * XXX: avoid to use it unless you can't */
00069     ACCESS_SET_PRIVATE_ID_STATE = 0x1000, /* arg1= int i_private_data, bool b_selected    res=can fail */
00070     ACCESS_SET_PRIVATE_ID_CA,             /* arg1= int i_program_number, uint16_t i_vpid, uint16_t i_apid1, uint16_t i_apid2, uint16_t i_apid3, uint8_t i_length, uint8_t *p_data */
00071     ACCESS_GET_PRIVATE_ID_STATE,          /* arg1=int i_private_data arg2=bool *          res=can fail */
00072 };
00073 
00074 struct access_t
00075 {
00076     VLC_COMMON_MEMBERS
00077 
00078     /* Module properties */
00079     module_t    *p_module;
00080 
00081     /* Access name (empty if non forced) */
00082     char        *psz_access;
00083     char        *psz_location; /**< Location (URL with the scheme stripped) */
00084     char        *psz_filepath; /**< Local file path (if applicable) */
00085 
00086     /* Access can fill this entry to force a demuxer
00087      * XXX: fill it once you know for sure you will succeed
00088      * (if you fail, this value won't be reseted */
00089     char        *psz_demux;
00090 
00091     /* pf_read/pf_block is used to read data.
00092      * XXX A access should set one and only one of them */
00093     ssize_t     (*pf_read) ( access_t *, uint8_t *, size_t );  /* Return -1 if no data yet, 0 if no more data, else real data read */
00094     block_t    *(*pf_block)( access_t * );                  /* return a block of data in his 'natural' size, NULL if not yet data or eof */
00095 
00096     /* Called for each seek.
00097      * XXX can be null */
00098     int         (*pf_seek) ( access_t *, uint64_t );         /* can be null if can't seek */
00099 
00100     /* Used to retreive and configure the access
00101      * XXX mandatory. look at access_query_e to know what query you *have to* support */
00102     int         (*pf_control)( access_t *, int i_query, va_list args);
00103 
00104     /* Access has to maintain them uptodate */
00105     struct
00106     {
00107         unsigned int i_update;  /* Access sets them on change,
00108                                    Input removes them once take into account*/
00109 
00110         uint64_t     i_size;    /* Write only for access, read only for input */
00111         uint64_t     i_pos;     /* idem */
00112         bool         b_eof;     /* idem */
00113 
00114         int          i_title;    /* idem, start from 0 (could be menu) */
00115         int          i_seekpoint;/* idem, start from 0 */
00116     } info;
00117     access_sys_t *p_sys;
00118 
00119     /* Weak link to parent input */
00120     input_thread_t *p_input;
00121 };
00122 
00123 static inline int access_vaControl( access_t *p_access, int i_query, va_list args )
00124 {
00125     if( !p_access ) return VLC_EGENERIC;
00126     return p_access->pf_control( p_access, i_query, args );
00127 }
00128 
00129 static inline int access_Control( access_t *p_access, int i_query, ... )
00130 {
00131     va_list args;
00132     int     i_result;
00133 
00134     va_start( args, i_query );
00135     i_result = access_vaControl( p_access, i_query, args );
00136     va_end( args );
00137     return i_result;
00138 }
00139 
00140 static inline void access_InitFields( access_t *p_a )
00141 {
00142     p_a->info.i_update = 0;
00143     p_a->info.i_size = 0;
00144     p_a->info.i_pos = 0;
00145     p_a->info.b_eof = false;
00146     p_a->info.i_title = 0;
00147     p_a->info.i_seekpoint = 0;
00148 }
00149 
00150 /**
00151  * This function will return the parent input of this access.
00152  * It is retained. It can return NULL.
00153  */
00154 VLC_API input_thread_t * access_GetParentInput( access_t *p_access ) VLC_USED;
00155 
00156 #define ACCESS_SET_CALLBACKS( read, block, control, seek ) \
00157     do { \
00158         p_access->pf_read = (read); \
00159         p_access->pf_block = (block); \
00160         p_access->pf_control = (control); \
00161         p_access->pf_seek = (seek); \
00162     } while(0)
00163 
00164 #define STANDARD_READ_ACCESS_INIT \
00165     do { \
00166         access_InitFields( p_access ); \
00167         ACCESS_SET_CALLBACKS( Read, NULL, Control, Seek ); \
00168         p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) ); \
00169         if( !p_sys ) return VLC_ENOMEM;\
00170     } while(0);
00171 
00172 #define STANDARD_BLOCK_ACCESS_INIT \
00173     do { \
00174         access_InitFields( p_access ); \
00175         ACCESS_SET_CALLBACKS( NULL, Block, Control, Seek ); \
00176         p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) ); \
00177         if( !p_sys ) return VLC_ENOMEM; \
00178     } while(0);
00179 
00180 /**
00181  * @}
00182  */
00183 
00184 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines