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 VLC authors and VideoLAN
00005  * $Id: c9298367b3249ea233e62262695d09bc450a28e4 $
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_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     char        *psz_access;
00061     /* Real or virtual path (it can only be changed during stream_t opening) */
00062     char        *psz_path;
00063 
00064     /* Stream source for stream filter */
00065     stream_t *p_source;
00066 
00067     /* */
00068     int      (*pf_read)   ( stream_t *, void *p_read, unsigned int i_read );
00069     int      (*pf_peek)   ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek );
00070     int      (*pf_control)( stream_t *, int i_query, va_list );
00071 
00072     /* */
00073     void     (*pf_destroy)( stream_t *);
00074 
00075     /* Private data for module */
00076     stream_sys_t *p_sys;
00077 
00078     /* Text reader state */
00079     stream_text_t *p_text;
00080 
00081     /* Weak link to parent input */
00082     input_thread_t *p_input;
00083 };
00084 
00085 /**
00086  * Possible commands to send to stream_Control() and stream_vaControl()
00087  */
00088 enum stream_query_e
00089 {
00090     /* capabilities */
00091     STREAM_CAN_SEEK,            /**< arg1= bool *   res=cannot fail*/
00092     STREAM_CAN_FASTSEEK,        /**< arg1= bool *   res=cannot fail*/
00093 
00094     /* */
00095     STREAM_SET_POSITION,        /**< arg1= uint64_t       res=can fail  */
00096     STREAM_GET_POSITION,        /**< arg1= uint64_t *     res=cannot fail*/
00097 
00098     STREAM_GET_SIZE,            /**< arg1= uint64_t *     res=cannot fail (0 if no sense)*/
00099 
00100     /* Special for direct access control from demuxer.
00101      * XXX: avoid using it by all means */
00102     STREAM_CONTROL_ACCESS,  /* arg1= int i_access_query, args   res: can fail
00103                              if access unreachable or access control answer */
00104 
00105     /* You should update size of source if any and then update size 
00106      * FIXME find a way to avoid it */
00107     STREAM_UPDATE_SIZE,
00108 
00109     /* */
00110     STREAM_GET_CONTENT_TYPE,    /**< arg1= char **         res=can fail */
00111 
00112     /* XXX only data read through stream_Read/Block will be recorded */
00113     STREAM_SET_RECORD_STATE,     /**< arg1=bool, arg2=const char *psz_ext (if arg1 is true)  res=can fail */
00114 };
00115 
00116 VLC_API int stream_Read( stream_t *s, void *p_read, int i_read );
00117 VLC_API int stream_Peek( stream_t *s, const uint8_t **pp_peek, int i_peek );
00118 VLC_API int stream_vaControl( stream_t *s, int i_query, va_list args );
00119 VLC_API void stream_Delete( stream_t *s );
00120 VLC_API int stream_Control( stream_t *s, int i_query, ... );
00121 VLC_API block_t * stream_Block( stream_t *s, int i_size );
00122 VLC_API block_t * stream_BlockRemaining( stream_t *s, int i_max_size );
00123 VLC_API char * stream_ReadLine( stream_t * );
00124 
00125 /**
00126  * Get the current position in a stream
00127  */
00128 static inline int64_t stream_Tell( stream_t *s )
00129 {
00130     uint64_t i_pos;
00131     stream_Control( s, STREAM_GET_POSITION, &i_pos );
00132     if( i_pos >> 62 )
00133         return (int64_t)1 << 62;
00134     return i_pos;
00135 }
00136 
00137 /**
00138  * Get the size of the stream.
00139  */
00140 static inline int64_t stream_Size( stream_t *s )
00141 {
00142     uint64_t i_pos;
00143     stream_Control( s, STREAM_GET_SIZE, &i_pos );
00144     if( i_pos >> 62 )
00145         return (int64_t)1 << 62;
00146     return i_pos;
00147 }
00148 
00149 static inline int stream_Seek( stream_t *s, uint64_t i_pos )
00150 {
00151     return stream_Control( s, STREAM_SET_POSITION, i_pos );
00152 }
00153 
00154 /**
00155  * Get the Content-Type of a stream, or NULL if unknown.
00156  * Result must be free()'d.
00157  */
00158 static inline char *stream_ContentType( stream_t *s )
00159 {
00160     char *res;
00161     if( stream_Control( s, STREAM_GET_CONTENT_TYPE, &res ) )
00162         return NULL;
00163     return res;
00164 }
00165 
00166 /**
00167  * Create a special stream and a demuxer, this allows chaining demuxers
00168  * You must delete it using stream_Delete.
00169  */
00170 VLC_API stream_t * stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *out );
00171 
00172 /**
00173  * Send data to a stream_t handle created by stream_DemuxNew.
00174  */
00175 VLC_API void stream_DemuxSend( stream_t *s, block_t *p_block );
00176 
00177 /**
00178  * Create a stream_t reading from memory.
00179  * You must delete it using stream_Delete.
00180  */
00181 VLC_API stream_t * stream_MemoryNew(vlc_object_t *p_obj, uint8_t *p_buffer, uint64_t i_size, bool b_preserve_memory );
00182 #define stream_MemoryNew( a, b, c, d ) stream_MemoryNew( VLC_OBJECT(a), b, c, d )
00183 
00184 /**
00185  * Create a stream_t reading from a URL.
00186  * You must delete it using stream_Delete.
00187  */
00188 VLC_API stream_t * stream_UrlNew(vlc_object_t *p_this, const char *psz_url );
00189 #define stream_UrlNew( a, b ) stream_UrlNew( VLC_OBJECT(a), b )
00190 
00191 
00192 /**
00193  * Try to add a stream filter to an open stream.
00194  * @return New stream to use, or NULL if the filter could not be added.
00195  **/
00196 VLC_API stream_t* stream_FilterNew( stream_t *p_source, const char *psz_stream_filter );
00197 /**
00198  * @}
00199  */
00200 
00201 # ifdef __cplusplus
00202 }
00203 # endif
00204 
00205 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines