]> git.sesse.net Git - vlc/blob - include/vlc_input_item.h
update meta request API to allow overriding
[vlc] / include / vlc_input_item.h
1 /*****************************************************************************
2  * vlc_input_item.h: Core input item
3  *****************************************************************************
4  * Copyright (C) 1999-2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef VLC_INPUT_ITEM_H
26 #define VLC_INPUT_ITEM_H 1
27
28 /**
29  * \file
30  * This file defines functions, structures and enums for input items in vlc
31  */
32
33 #include <vlc_meta.h>
34 #include <vlc_epg.h>
35 #include <vlc_events.h>
36
37 #include <string.h>
38
39 /*****************************************************************************
40  * input_item_t: Describes an input and is used to spawn input_thread_t objects
41  *****************************************************************************/
42 struct info_t
43 {
44     char *psz_name;            /**< Name of this info */
45     char *psz_value;           /**< Value of the info */
46 };
47
48 struct info_category_t
49 {
50     char   *psz_name;      /**< Name of this category */
51     int    i_infos;        /**< Number of infos in the category */
52     struct info_t **pp_infos;     /**< Pointer to an array of infos */
53 };
54
55 struct input_item_t
56 {
57     int        i_id;                 /**< Identifier of the item */
58
59     char       *psz_name;            /**< text describing this item */
60     char       *psz_uri;             /**< mrl of this item */
61
62     int        i_options;            /**< Number of input options */
63     char       **ppsz_options;       /**< Array of input options */
64     uint8_t    *optflagv;            /**< Some flags of input options */
65     unsigned   optflagc;
66
67     mtime_t    i_duration;           /**< Duration in microseconds */
68
69
70     int        i_categories;         /**< Number of info categories */
71     info_category_t **pp_categories; /**< Pointer to the first info category */
72
73     int         i_es;                /**< Number of es format descriptions */
74     es_format_t **es;                /**< Es formats */
75
76     input_stats_t *p_stats;          /**< Statistics */
77     int           i_nb_played;       /**< Number of times played */
78
79     vlc_meta_t *p_meta;
80
81     int         i_epg;               /**< Number of EPG entries */
82     vlc_epg_t   **pp_epg;            /**< EPG entries */
83
84     vlc_event_manager_t event_manager;
85
86     vlc_mutex_t lock;                 /**< Lock for the item */
87
88     uint8_t     i_type;              /**< Type (file, disc, ... see input_item_type_e) */
89     bool        b_fixed_name;        /**< Can the interface change the name ?*/
90     bool        b_error_when_reading;/**< Error When Reading */
91 };
92
93 TYPEDEF_ARRAY(input_item_t*, input_item_array_t)
94
95 enum input_item_type_e
96 {
97     ITEM_TYPE_UNKNOWN,
98     ITEM_TYPE_FILE,
99     ITEM_TYPE_DIRECTORY,
100     ITEM_TYPE_DISC,
101     ITEM_TYPE_CDDA,
102     ITEM_TYPE_CARD,
103     ITEM_TYPE_NET,
104     ITEM_TYPE_PLAYLIST,
105     ITEM_TYPE_NODE,
106
107     /* This one is not a real type but the number of input_item types. */
108     ITEM_TYPE_NUMBER
109 };
110
111 struct input_item_node_t
112 {
113     input_item_t *         p_item;
114     int                    i_children;
115     input_item_node_t      **pp_children;
116     input_item_node_t      *p_parent;
117 };
118
119 VLC_API void input_item_CopyOptions( input_item_t *p_parent, input_item_t *p_child );
120 VLC_API void input_item_SetName( input_item_t *p_item, const char *psz_name );
121
122 /**
123  * Add one subitem to this item
124  *
125  * This won't hold the item, but can tell to interested third parties
126  * Like the playlist, that there is a new sub item. With this design
127  * It is not the input item's responsability to keep all the ref of
128  * the input item children.
129  *
130  * Sends a vlc_InputItemSubItemTreeAdded and a vlc_InputItemSubItemAdded event
131  */
132 VLC_API void input_item_PostSubItem( input_item_t *p_parent, input_item_t *p_child );
133
134 /**
135  * Start adding multiple subitems.
136  *
137  * Create a root node to hold a tree of subitems for given item
138  */
139 VLC_API input_item_node_t * input_item_node_Create( input_item_t *p_input ) VLC_USED;
140
141 /**
142  * Add a new child node to this parent node that will point to this subitem.
143  */
144 VLC_API input_item_node_t * input_item_node_AppendItem( input_item_node_t *p_node, input_item_t *p_item );
145
146 /**
147  * Add an already created node to children of this parent node.
148  */
149 VLC_API void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t *p_child );
150
151 /**
152  * Delete a node created with input_item_node_Create() and all its children.
153  */
154 VLC_API void input_item_node_Delete( input_item_node_t *p_node );
155
156 /**
157  * End adding multiple subitems.
158  *
159  * Sends a vlc_InputItemSubItemTreeAdded event to notify that the item pointed to
160  * by the given root node has created new subitems that are pointed to by all the
161  * children of the node.
162  *
163  * Also sends vlc_InputItemSubItemAdded event for every child under the given root node;
164  *
165  * In the end deletes the node and all its children nodes.
166  */
167 VLC_API void input_item_node_PostAndDelete( input_item_node_t *p_node );
168
169
170 /**
171  * Option flags
172  */
173 enum input_item_option_e
174 {
175     /* Allow VLC to trust the given option.
176      * By default options are untrusted */
177     VLC_INPUT_OPTION_TRUSTED = 0x2,
178
179     /* Add the option, unless the same option
180      * is already present. */
181     VLC_INPUT_OPTION_UNIQUE  = 0x100,
182
183     /* Search for an existing option in the format
184      * option=value and replaces the first one found.
185      * Else, the new option is added.
186      * This option and VLC_INPUT_OPTION_UNIQUE are
187      * mutually exclusive. */
188     VLC_INPUT_OPTION_REPLACE = 0x200,
189 };
190
191 /**
192  * This function allows to add an option to an existing input_item_t.
193  */
194 VLC_API int input_item_AddOption(input_item_t *, const char *, unsigned i_flags );
195
196 /* */
197 VLC_API bool input_item_HasErrorWhenReading( input_item_t * );
198 VLC_API void input_item_SetMeta( input_item_t *, vlc_meta_type_t meta_type, const char *psz_val );
199 VLC_API bool input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz );
200 VLC_API char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type ) VLC_USED;
201 VLC_API char * input_item_GetName( input_item_t * p_i ) VLC_USED;
202 VLC_API char * input_item_GetTitleFbName( input_item_t * p_i ) VLC_USED;
203 VLC_API char * input_item_GetURI( input_item_t * p_i ) VLC_USED;
204 VLC_API void input_item_SetURI( input_item_t * p_i, const char *psz_uri );
205 VLC_API mtime_t input_item_GetDuration( input_item_t * p_i );
206 VLC_API void input_item_SetDuration( input_item_t * p_i, mtime_t i_duration );
207 VLC_API bool input_item_IsPreparsed( input_item_t *p_i );
208 VLC_API bool input_item_IsArtFetched( input_item_t *p_i );
209
210 #define INPUT_META( name ) \
211 static inline \
212 void input_item_Set ## name (input_item_t *p_input, const char *val) \
213 { \
214     input_item_SetMeta (p_input, vlc_meta_ ## name, val); \
215 } \
216 static inline \
217 char *input_item_Get ## name (input_item_t *p_input) \
218 { \
219     return input_item_GetMeta (p_input, vlc_meta_ ## name); \
220 }
221
222 INPUT_META(Title)
223 INPUT_META(Artist)
224 INPUT_META(Genre)
225 INPUT_META(Copyright)
226 INPUT_META(Album)
227 INPUT_META(TrackNumber)
228 INPUT_META(Description)
229 INPUT_META(Rating)
230 INPUT_META(Date)
231 INPUT_META(Setting)
232 INPUT_META(URL)
233 INPUT_META(Language)
234 INPUT_META(NowPlaying)
235 INPUT_META(Publisher)
236 INPUT_META(EncodedBy)
237 INPUT_META(ArtworkURL)
238 INPUT_META(TrackID)
239 INPUT_META(TrackTotal)
240 INPUT_META(Director)
241 INPUT_META(Season)
242 INPUT_META(Episode)
243 INPUT_META(ShowName)
244 INPUT_META(Actors)
245
246 #define input_item_SetTrackNum input_item_SetTrackNumber
247 #define input_item_GetTrackNum input_item_GetTrackNumber
248 #define input_item_SetArtURL   input_item_SetArtworkURL
249 #define input_item_GetArtURL   input_item_GetArtworkURL
250
251 VLC_API char * input_item_GetInfo( input_item_t *p_i, const char *psz_cat,const char *psz_name ) VLC_USED;
252 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 );
253 VLC_API int input_item_DelInfo( input_item_t *p_i, const char *psz_cat, const char *psz_name );
254 VLC_API void input_item_ReplaceInfos( input_item_t *, info_category_t * );
255 VLC_API void input_item_MergeInfos( input_item_t *, info_category_t * );
256
257 /**
258  * This function creates a new input_item_t with the provided information.
259  *
260  * XXX You may also use input_item_New or input_item_NewExt as they need
261  * less arguments.
262  */
263 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;
264
265 /**
266  * This function creates a new input_item_t with the provided information.
267  *
268  * Provided for convenience.
269  */
270 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;
271
272 /**
273  * This function creates a new input_item_t with the provided information.
274  *
275  * Provided for convenience.
276  */
277 #define input_item_New( a,b ) input_item_NewExt( a, b, 0, NULL, 0, -1 )
278
279 /**
280  * This function creates a new input_item_t as a copy of another.
281  */
282 VLC_API input_item_t * input_item_Copy(input_item_t * ) VLC_USED;
283
284 /** Holds an input item, i.e. creates a new reference. */
285 VLC_API input_item_t *input_item_Hold(input_item_t *);
286
287 /** Releases an input item, i.e. decrements its reference counter. */
288 VLC_API void input_item_Release(input_item_t *);
289
290 /* Historical hack... */
291 #define vlc_gc_incref(i) input_item_Hold(i)
292 #define vlc_gc_decref(i) input_item_Release(i)
293
294 typedef enum input_item_meta_request_option_t
295 {
296     META_REQUEST_OPTION_NONE = 0,
297     META_REQUEST_OPTION_LOCAL = 1 << 0,
298     META_REQUEST_OPTION_NETWORK = 1 << 1,
299     META_REQUEST_OPTION_ANY = 1 << 2
300 } input_item_meta_request_option_t;
301
302 VLC_API int libvlc_MetaRequest(libvlc_int_t *, input_item_t *,
303                                input_item_meta_request_option_t );
304 VLC_API int libvlc_ArtRequest(libvlc_int_t *, input_item_t *,
305                               input_item_meta_request_option_t );
306
307 /******************
308  * Input stats
309  ******************/
310 struct input_stats_t
311 {
312     vlc_mutex_t         lock;
313
314     /* Input */
315     int64_t i_read_packets;
316     int64_t i_read_bytes;
317     float f_input_bitrate;
318     float f_average_input_bitrate;
319
320     /* Demux */
321     int64_t i_demux_read_packets;
322     int64_t i_demux_read_bytes;
323     float f_demux_bitrate;
324     float f_average_demux_bitrate;
325     int64_t i_demux_corrupted;
326     int64_t i_demux_discontinuity;
327
328     /* Decoders */
329     int64_t i_decoded_audio;
330     int64_t i_decoded_video;
331
332     /* Vout */
333     int64_t i_displayed_pictures;
334     int64_t i_lost_pictures;
335
336     /* Sout */
337     int64_t i_sent_packets;
338     int64_t i_sent_bytes;
339     float f_send_bitrate;
340
341     /* Aout */
342     int64_t i_played_abuffers;
343     int64_t i_lost_abuffers;
344 };
345
346 #endif