vlc_input_item.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_input_item.h: Core input item
00003  *****************************************************************************
00004  * Copyright (C) 1999-2009 VLC authors and VideoLAN
00005  * $Id: 686957288e574ef911209db70178568c9ba61a39 $
00006  *
00007  * Authors: Christophe Massiot <massiot@via.ecp.fr>
00008  *          Laurent Aimar <fenrir@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU Lesser General Public License as published by
00012  * the Free Software Foundation; either version 2.1 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018  * GNU Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public License
00021  * along with this program; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VLC_INPUT_ITEM_H
00026 #define VLC_INPUT_ITEM_H 1
00027 
00028 /**
00029  * \file
00030  * This file defines functions, structures and enums for input items in vlc
00031  */
00032 
00033 #include <vlc_meta.h>
00034 #include <vlc_epg.h>
00035 #include <vlc_events.h>
00036 
00037 #include <string.h>
00038 
00039 /*****************************************************************************
00040  * input_item_t: Describes an input and is used to spawn input_thread_t objects
00041  *****************************************************************************/
00042 struct info_t
00043 {
00044     char *psz_name;            /**< Name of this info */
00045     char *psz_value;           /**< Value of the info */
00046 };
00047 
00048 struct info_category_t
00049 {
00050     char   *psz_name;      /**< Name of this category */
00051     int    i_infos;        /**< Number of infos in the category */
00052     struct info_t **pp_infos;     /**< Pointer to an array of infos */
00053 };
00054 
00055 struct input_item_t
00056 {
00057     VLC_GC_MEMBERS
00058     int        i_id;                 /**< Identifier of the item */
00059 
00060     char       *psz_name;            /**< text describing this item */
00061     char       *psz_uri;             /**< mrl of this item */
00062 
00063     int        i_options;            /**< Number of input options */
00064     char       **ppsz_options;       /**< Array of input options */
00065     uint8_t    *optflagv;            /**< Some flags of input options */
00066     unsigned   optflagc;
00067 
00068     mtime_t    i_duration;           /**< Duration in microseconds */
00069 
00070 
00071     int        i_categories;         /**< Number of info categories */
00072     info_category_t **pp_categories; /**< Pointer to the first info category */
00073 
00074     int         i_es;                /**< Number of es format descriptions */
00075     es_format_t **es;                /**< Es formats */
00076 
00077     input_stats_t *p_stats;          /**< Statistics */
00078     int           i_nb_played;       /**< Number of times played */
00079 
00080     vlc_meta_t *p_meta;
00081 
00082     int         i_epg;               /**< Number of EPG entries */
00083     vlc_epg_t   **pp_epg;            /**< EPG entries */
00084 
00085     vlc_event_manager_t event_manager;
00086 
00087     vlc_mutex_t lock;                 /**< Lock for the item */
00088 
00089     uint8_t     i_type;              /**< Type (file, disc, ... see input_item_type_e) */
00090     bool        b_fixed_name;        /**< Can the interface change the name ?*/
00091     bool        b_error_when_reading;/**< Error When Reading */
00092 };
00093 
00094 enum input_item_type_e
00095 {
00096     ITEM_TYPE_UNKNOWN,
00097     ITEM_TYPE_FILE,
00098     ITEM_TYPE_DIRECTORY,
00099     ITEM_TYPE_DISC,
00100     ITEM_TYPE_CDDA,
00101     ITEM_TYPE_CARD,
00102     ITEM_TYPE_NET,
00103     ITEM_TYPE_PLAYLIST,
00104     ITEM_TYPE_NODE,
00105 
00106     /* This one is not a real type but the number of input_item types. */
00107     ITEM_TYPE_NUMBER
00108 };
00109 
00110 struct input_item_node_t
00111 {
00112     input_item_t *         p_item;
00113     int                    i_children;
00114     input_item_node_t      **pp_children;
00115     input_item_node_t      *p_parent;
00116 };
00117 
00118 VLC_API void input_item_CopyOptions( input_item_t *p_parent, input_item_t *p_child );
00119 VLC_API void input_item_SetName( input_item_t *p_item, const char *psz_name );
00120 
00121 /**
00122  * Add one subitem to this item
00123  *
00124  * This won't hold the item, but can tell to interested third parties
00125  * Like the playlist, that there is a new sub item. With this design
00126  * It is not the input item's responsability to keep all the ref of
00127  * the input item children.
00128  *
00129  * Sends a vlc_InputItemSubItemTreeAdded and a vlc_InputItemSubItemAdded event
00130  */
00131 VLC_API void input_item_PostSubItem( input_item_t *p_parent, input_item_t *p_child );
00132 
00133 /**
00134  * Start adding multiple subitems.
00135  *
00136  * Create a root node to hold a tree of subitems for given item
00137  */
00138 VLC_API input_item_node_t * input_item_node_Create( input_item_t *p_input ) VLC_USED;
00139 
00140 /**
00141  * Add a new child node to this parent node that will point to this subitem.
00142  */
00143 VLC_API input_item_node_t * input_item_node_AppendItem( input_item_node_t *p_node, input_item_t *p_item );
00144 
00145 /**
00146  * Add an already created node to children of this parent node.
00147  */
00148 VLC_API void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t *p_child );
00149 
00150 /**
00151  * Delete a node created with input_item_node_Create() and all its children.
00152  */
00153 VLC_API void input_item_node_Delete( input_item_node_t *p_node );
00154 
00155 /**
00156  * End adding multiple subitems.
00157  *
00158  * Sends a vlc_InputItemSubItemTreeAdded event to notify that the item pointed to
00159  * by the given root node has created new subitems that are pointed to by all the
00160  * children of the node.
00161  *
00162  * Also sends vlc_InputItemSubItemAdded event for every child under the given root node;
00163  *
00164  * In the end deletes the node and all its children nodes.
00165  */
00166 VLC_API void input_item_node_PostAndDelete( input_item_node_t *p_node );
00167 
00168 
00169 /**
00170  * Option flags
00171  */
00172 enum input_item_option_e
00173 {
00174     /* Allow VLC to trust the given option.
00175      * By default options are untrusted */
00176     VLC_INPUT_OPTION_TRUSTED = 0x2,
00177 
00178     /* Change the value associated to an option if already present, otherwise
00179      * add the option */
00180     VLC_INPUT_OPTION_UNIQUE  = 0x100,
00181 };
00182 
00183 /**
00184  * This function allows to add an option to an existing input_item_t.
00185  */
00186 VLC_API int input_item_AddOption(input_item_t *, const char *, unsigned i_flags );
00187 
00188 /* */
00189 VLC_API bool input_item_HasErrorWhenReading( input_item_t * );
00190 VLC_API void input_item_SetMeta( input_item_t *, vlc_meta_type_t meta_type, const char *psz_val );
00191 VLC_API bool input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz );
00192 VLC_API char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type ) VLC_USED;
00193 VLC_API char * input_item_GetName( input_item_t * p_i ) VLC_USED;
00194 VLC_API char * input_item_GetTitleFbName( input_item_t * p_i ) VLC_USED;
00195 VLC_API char * input_item_GetURI( input_item_t * p_i ) VLC_USED;
00196 VLC_API void input_item_SetURI( input_item_t * p_i, const char *psz_uri );
00197 VLC_API mtime_t input_item_GetDuration( input_item_t * p_i );
00198 VLC_API void input_item_SetDuration( input_item_t * p_i, mtime_t i_duration );
00199 VLC_API bool input_item_IsPreparsed( input_item_t *p_i );
00200 VLC_API bool input_item_IsArtFetched( input_item_t *p_i );
00201 
00202 #define INPUT_META( name ) \
00203 static inline \
00204 void input_item_Set ## name (input_item_t *p_input, const char *val) \
00205 { \
00206     input_item_SetMeta (p_input, vlc_meta_ ## name, val); \
00207 } \
00208 static inline \
00209 char *input_item_Get ## name (input_item_t *p_input) \
00210 { \
00211     return input_item_GetMeta (p_input, vlc_meta_ ## name); \
00212 }
00213 
00214 INPUT_META(Title)
00215 INPUT_META(Artist)
00216 INPUT_META(Genre)
00217 INPUT_META(Copyright)
00218 INPUT_META(Album)
00219 INPUT_META(TrackNumber)
00220 INPUT_META(Description)
00221 INPUT_META(Rating)
00222 INPUT_META(Date)
00223 INPUT_META(Setting)
00224 INPUT_META(URL)
00225 INPUT_META(Language)
00226 INPUT_META(NowPlaying)
00227 INPUT_META(Publisher)
00228 INPUT_META(EncodedBy)
00229 INPUT_META(ArtworkURL)
00230 INPUT_META(TrackID)
00231 
00232 #define input_item_SetTrackNum input_item_SetTrackNumber
00233 #define input_item_GetTrackNum input_item_GetTrackNumber
00234 #define input_item_SetArtURL   input_item_SetArtworkURL
00235 #define input_item_GetArtURL   input_item_GetArtworkURL
00236 
00237 VLC_API char * input_item_GetInfo( input_item_t *p_i, const char *psz_cat,const char *psz_name ) VLC_USED;
00238 VLC_API int input_item_AddInfo( input_item_t *p_i, const char *psz_cat, const char *psz_name, const char *psz_format, ... ) VLC_FORMAT( 4, 5 );
00239 VLC_API int input_item_DelInfo( input_item_t *p_i, const char *psz_cat, const char *psz_name );
00240 VLC_API void input_item_ReplaceInfos( input_item_t *, info_category_t * );
00241 VLC_API void input_item_MergeInfos( input_item_t *, info_category_t * );
00242 
00243 /**
00244  * This function creates a new input_item_t with the provided information.
00245  *
00246  * XXX You may also use input_item_New or input_item_NewExt as they need
00247  * less arguments.
00248  */
00249 VLC_API input_item_t * input_item_NewWithType( const char *psz_uri, const char *psz_name, int i_options, const char *const *ppsz_options, unsigned i_option_flags, mtime_t i_duration, int i_type ) VLC_USED;
00250 
00251 /**
00252  * This function creates a new input_item_t with the provided information.
00253  *
00254  * Provided for convenience.
00255  */
00256 VLC_API input_item_t * input_item_NewExt( const char *psz_uri, const char *psz_name, int i_options, const char *const *ppsz_options, unsigned i_option_flags, mtime_t i_duration ) VLC_USED;
00257 
00258 /**
00259  * This function creates a new input_item_t with the provided information.
00260  *
00261  * Provided for convenience.
00262  */
00263 #define input_item_New( a,b ) input_item_NewExt( a, b, 0, NULL, 0, -1 )
00264 
00265 /**
00266  * This function creates a new input_item_t as a copy of another.
00267  */
00268 VLC_API input_item_t * input_item_Copy(input_item_t * ) VLC_USED;
00269 
00270 
00271 /******************
00272  * Input stats
00273  ******************/
00274 struct input_stats_t
00275 {
00276     vlc_mutex_t         lock;
00277 
00278     /* Input */
00279     int64_t i_read_packets;
00280     int64_t i_read_bytes;
00281     float f_input_bitrate;
00282     float f_average_input_bitrate;
00283 
00284     /* Demux */
00285     int64_t i_demux_read_packets;
00286     int64_t i_demux_read_bytes;
00287     float f_demux_bitrate;
00288     float f_average_demux_bitrate;
00289     int64_t i_demux_corrupted;
00290     int64_t i_demux_discontinuity;
00291 
00292     /* Decoders */
00293     int64_t i_decoded_audio;
00294     int64_t i_decoded_video;
00295 
00296     /* Vout */
00297     int64_t i_displayed_pictures;
00298     int64_t i_lost_pictures;
00299 
00300     /* Sout */
00301     int64_t i_sent_packets;
00302     int64_t i_sent_bytes;
00303     float f_send_bitrate;
00304 
00305     /* Aout */
00306     int64_t i_played_abuffers;
00307     int64_t i_lost_abuffers;
00308 };
00309 
00310 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines