vlc_stream.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_stream.h: Stream (between access and demux) descriptor and methods
00003  *****************************************************************************
00004  * Copyright (C) 1999-2004 the VideoLAN team
00005  * $Id: 1d499890c3f69355966afccc066f5bbd74065d30 $
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_STREAM_H
00025 #define VLC_STREAM_H 1
00026 
00027 #include <vlc_block.h>
00028 
00029 /**
00030  * \file
00031  * This file defines structures and functions for stream (between access and demux) descriptor in vlc
00032  */
00033 
00034 # ifdef __cplusplus
00035 extern "C" {
00036 # endif
00037 
00038 /**
00039  * \defgroup stream Stream
00040  *
00041  *  This will allow you to easily handle read/seek in demuxer modules.
00042  * @{
00043  */
00044 
00045 /* Opaque definition for text reader context */
00046 typedef struct stream_text_t stream_text_t;
00047 
00048 /**
00049  * stream_t definition
00050  */
00051 
00052 struct stream_t
00053 {
00054     VLC_COMMON_MEMBERS
00055     bool        b_error;
00056 
00057     /* Module properties for stream filter */
00058     module_t    *p_module;
00059 
00060     /* Real or virtual path (it can only be changed during stream_t opening) */
00061     char        *psz_path;
00062 
00063     /* Stream source for stream filter */
00064     stream_t *p_source;
00065 
00066     /* */
00067     int      (*pf_read)   ( stream_t *, void *p_read, unsigned int i_read );
00068     int      (*pf_peek)   ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek );
00069     int      (*pf_control)( stream_t *, int i_query, va_list );
00070 
00071     /* */
00072     void     (*pf_destroy)( stream_t *);
00073 
00074     /* Private data for module */
00075     stream_sys_t *p_sys;
00076 
00077     /* Text reader state */
00078     stream_text_t *p_text;
00079 
00080     /* Weak link to parent input */
00081     input_thread_t *p_input;
00082 };
00083 
00084 /**
00085  * Possible commands to send to stream_Control() and stream_vaControl()
00086  */
00087 enum stream_query_e
00088 {
00089     /* capabilities */
00090     STREAM_CAN_SEEK,            /**< arg1= bool *   res=cannot fail*/
00091     STREAM_CAN_FASTSEEK,        /**< arg1= bool *   res=cannot fail*/
00092 
00093     /* */
00094     STREAM_SET_POSITION,        /**< arg1= uint64_t       res=can fail  */
00095     STREAM_GET_POSITION,        /**< arg1= uint64_t *     res=cannot fail*/
00096 
00097     STREAM_GET_SIZE,            /**< arg1= uint64_t *     res=cannot fail (0 if no sense)*/
00098 
00099     /* Special for direct access control from demuxer.
00100      * XXX: avoid using it by all means */
00101     STREAM_CONTROL_ACCESS,  /* arg1= int i_access_query, args   res: can fail
00102                              if access unreachable or access control answer */
00103 
00104     /* You should update size of source if any and then update size 
00105      * FIXME find a way to avoid it */
00106     STREAM_UPDATE_SIZE,
00107 
00108     /* */
00109     STREAM_GET_CONTENT_TYPE,    /**< arg1= char **         res=can fail */
00110 
00111     /* XXX only data read through stream_Read/Block will be recorded */
00112     STREAM_SET_RECORD_STATE,     /**< arg1=bool, arg2=const char *psz_ext (if arg1 is true)  res=can fail */
00113 };
00114 
00115 VLC_EXPORT( int, stream_Read, ( stream_t *s, void *p_read, int i_read ) );
00116 VLC_EXPORT( int, stream_Peek, ( stream_t *s, const uint8_t **pp_peek, int i_peek ) );
00117 VLC_EXPORT( int, stream_vaControl, ( stream_t *s, int i_query, va_list args ) );
00118 VLC_EXPORT( void, stream_Delete, ( stream_t *s ) );
00119 VLC_EXPORT( int, stream_Control, ( stream_t *s, int i_query, ... ) );
00120 VLC_EXPORT( block_t *, stream_Block, ( stream_t *s, int i_size ) );
00121 VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
00122 
00123 /**
00124  * Get the current position in a stream
00125  */
00126 static inline int64_t stream_Tell( stream_t *s )
00127 {
00128     uint64_t i_pos;
00129     stream_Control( s, STREAM_GET_POSITION, &i_pos );
00130     if( i_pos >> 62 )
00131         return (int64_t)1 << 62;
00132     return i_pos;
00133 }
00134 
00135 /**
00136  * Get the size of the stream.
00137  */
00138 static inline int64_t stream_Size( stream_t *s )
00139 {
00140     uint64_t i_pos;
00141     stream_Control( s, STREAM_GET_SIZE, &i_pos );
00142     if( i_pos >> 62 )
00143         return (int64_t)1 << 62;
00144     return i_pos;
00145 }
00146 
00147 static inline int stream_Seek( stream_t *s, uint64_t i_pos )
00148 {
00149     return stream_Control( s, STREAM_SET_POSITION, i_pos );
00150 }
00151 
00152 /**
00153  * Get the Content-Type of a stream, or NULL if unknown.
00154  * Result must be free()'d.
00155  */
00156 static inline char *stream_ContentType( stream_t *s )
00157 {
00158     char *res;
00159     if( stream_Control( s, STREAM_GET_CONTENT_TYPE, &res ) )
00160         return NULL;
00161     return res;
00162 }
00163 
00164 /**
00165  * Create a special stream and a demuxer, this allows chaining demuxers
00166  * You must delete it using stream_Delete.
00167  */
00168 VLC_EXPORT( stream_t *, stream_DemuxNew, ( demux_t *p_demux, const char *psz_demux, es_out_t *out ) );
00169 
00170 /**
00171  * Send data to a stream_t handle created by stream_DemuxNew.
00172  */
00173 VLC_EXPORT( void,      stream_DemuxSend,  ( stream_t *s, block_t *p_block ) );
00174 
00175 /**
00176  * Create a stream_t reading from memory.
00177  * You must delete it using stream_Delete.
00178  */
00179 VLC_EXPORT( stream_t *, stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, uint64_t i_size, bool b_preserve_memory ) );
00180 #define stream_MemoryNew( a, b, c, d ) stream_MemoryNew( VLC_OBJECT(a), b, c, d )
00181 
00182 /**
00183  * Create a stream_t reading from an URL.
00184  * You must delete it using stream_Delete.
00185  */
00186 VLC_EXPORT( stream_t *, stream_UrlNew, (vlc_object_t *p_this, const char *psz_url ) );
00187 #define stream_UrlNew( a, b ) stream_UrlNew( VLC_OBJECT(a), b )
00188 
00189 
00190 /**
00191  * Try to add a stream filter to an open stream.
00192  * @return New stream to use, or NULL if the filter could not be added.
00193  **/
00194 VLC_EXPORT( stream_t*, stream_FilterNew, ( stream_t *p_source, const char *psz_stream_filter ) );
00195 /**
00196  * @}
00197  */
00198 
00199 # ifdef __cplusplus
00200 }
00201 # endif
00202 
00203 #endif

Generated on Mon Nov 22 07:55:20 2010 for VLC by  doxygen 1.5.6