qml: don't base MusicArtist to MusicAlbums, create it separately
[vlc.git] / include / vlc_input_item.h
blob1c99f6c0122f98390dc7ec69ca98878cd8c30cd8
1 /*****************************************************************************
2 * vlc_input_item.h: Core input item
3 *****************************************************************************
4 * Copyright (C) 1999-2009 VLC authors and VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
7 * Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_INPUT_ITEM_H
25 #define VLC_INPUT_ITEM_H 1
27 /**
28 * \file
29 * This file defines functions, structures and enums for input items in vlc
32 #include <vlc_meta.h>
33 #include <vlc_epg.h>
34 #include <vlc_events.h>
35 #include <vlc_list.h>
37 #include <string.h>
39 typedef struct input_item_opaque input_item_opaque_t;
40 typedef struct input_item_slave input_item_slave_t;
41 typedef struct input_preparser_callbacks_t input_preparser_callbacks_t;
43 struct info_t
45 char *psz_name; /**< Name of this info */
46 char *psz_value; /**< Value of the info */
47 struct vlc_list node;
50 #define info_foreach(info, cat) vlc_list_foreach(info, cat, node)
52 struct info_category_t
54 char *psz_name; /**< Name of this category */
55 struct vlc_list infos; /**< Infos in the category */
58 enum input_item_type_e
60 ITEM_TYPE_UNKNOWN,
61 ITEM_TYPE_FILE,
62 ITEM_TYPE_DIRECTORY,
63 ITEM_TYPE_DISC,
64 ITEM_TYPE_CARD,
65 ITEM_TYPE_STREAM,
66 ITEM_TYPE_PLAYLIST,
67 ITEM_TYPE_NODE,
69 /* This one is not a real type but the number of input_item types. */
70 ITEM_TYPE_NUMBER
73 /**
74 * Describes an input and is used to spawn input_thread_t objects.
76 struct input_item_t
78 char *psz_name; /**< text describing this item */
79 char *psz_uri; /**< mrl of this item */
81 int i_options; /**< Number of input options */
82 char **ppsz_options; /**< Array of input options */
83 uint8_t *optflagv; /**< Some flags of input options */
84 unsigned optflagc;
85 input_item_opaque_t *opaques; /**< List of opaque pointer values */
87 vlc_tick_t i_duration; /**< Duration in vlc ticks */
90 int i_categories; /**< Number of info categories */
91 info_category_t **pp_categories; /**< Pointer to the first info category */
93 int i_es; /**< Number of es format descriptions */
94 es_format_t **es; /**< Es formats */
96 input_stats_t *p_stats; /**< Statistics */
98 vlc_meta_t *p_meta;
100 int i_epg; /**< Number of EPG entries */
101 vlc_epg_t **pp_epg; /**< EPG entries */
102 int64_t i_epg_time; /** EPG timedate as epoch time */
103 const vlc_epg_t *p_epg_table; /** running/selected program cur/next EPG table */
105 int i_slaves; /**< Number of slaves */
106 input_item_slave_t **pp_slaves; /**< Slave entries that will be loaded by
107 the input_thread */
109 vlc_event_manager_t event_manager;
111 vlc_mutex_t lock; /**< Lock for the item */
113 enum input_item_type_e i_type; /**< Type (file, disc, ... see input_item_type_e) */
114 bool b_net; /**< Net: always true for TYPE_STREAM, it
115 depends for others types */
116 bool b_error_when_reading;/**< Error When Reading */
118 int i_preparse_depth; /**< How many level of sub items can be preparsed:
119 -1: recursive, 0: none, >0: n levels */
121 bool b_preparse_interact; /**< Force interaction with the user when
122 preparsing.*/
125 #define INPUT_ITEM_URI_NOP "vlc://nop" /* dummy URI for node/directory items */
127 /* placeholder duration for items with no known duration at time of creation
128 * it may remain the duration for items like a node/directory */
129 #define INPUT_DURATION_UNSET VLC_TICK_INVALID
130 #define INPUT_DURATION_INDEFINITE (-1) /* item with a known indefinite duration (live/continuous source) */
132 enum input_item_net_type
134 ITEM_NET_UNKNOWN,
135 ITEM_NET,
136 ITEM_LOCAL
139 enum slave_type
141 SLAVE_TYPE_SPU,
142 SLAVE_TYPE_AUDIO,
145 enum slave_priority
147 SLAVE_PRIORITY_MATCH_NONE = 1,
148 SLAVE_PRIORITY_MATCH_RIGHT,
149 SLAVE_PRIORITY_MATCH_LEFT,
150 SLAVE_PRIORITY_MATCH_ALL,
151 SLAVE_PRIORITY_USER
154 /* Extensions must be in alphabetical order */
155 #define MASTER_EXTENSIONS \
156 "asf", "avi", "divx", \
157 "f4v", "flv", "m1v", \
158 "m2v", "m4v", "mkv", \
159 "mov", "mp2", "mp2v", \
160 "mp4", "mp4v", "mpe", \
161 "mpeg", "mpeg1", "mpeg2", \
162 "mpeg4", "mpg", "mpv2", \
163 "mxf", "ogv", "ogx", \
164 "ps", "vro","webm", \
165 "wmv", "wtv"
167 #define SLAVE_SPU_EXTENSIONS \
168 "aqt", "ass", "cdg", \
169 "dks", "idx", "jss", \
170 "mpl2", "mpsub", "pjs", \
171 "psb", "rt", "sami", "sbv", \
172 "scc", "smi", "srt", \
173 "ssa", "stl", "sub", \
174 "tt", "ttml", "usf", \
175 "vtt", "webvtt"
177 #define SLAVE_AUDIO_EXTENSIONS \
178 "aac", "ac3", "dts", \
179 "dtshd", "eac3", "flac", \
180 "m4a", "mp3", "pcm" \
182 struct input_item_slave
184 enum slave_type i_type; /**< Slave type (spu, audio) */
185 enum slave_priority i_priority; /**< Slave priority */
186 bool b_forced; /**< Slave should be selected */
187 char psz_uri[]; /**< Slave mrl */
190 struct input_item_node_t
192 input_item_t * p_item;
193 int i_children;
194 input_item_node_t **pp_children;
197 VLC_API void input_item_CopyOptions( input_item_t *p_child, input_item_t *p_parent );
198 VLC_API void input_item_SetName( input_item_t *p_item, const char *psz_name );
201 * Start adding multiple subitems.
203 * Create a root node to hold a tree of subitems for given item
205 VLC_API input_item_node_t * input_item_node_Create( input_item_t *p_input ) VLC_USED;
208 * Add a new child node to this parent node that will point to this subitem.
210 VLC_API input_item_node_t * input_item_node_AppendItem( input_item_node_t *p_node, input_item_t *p_item );
213 * Add an already created node to children of this parent node.
215 VLC_API void input_item_node_AppendNode( input_item_node_t *p_parent, input_item_node_t *p_child );
218 * Remove a node from its parent.
220 VLC_API void input_item_node_RemoveNode( input_item_node_t *parent,
221 input_item_node_t *child );
224 * Delete a node created with input_item_node_Create() and all its children.
226 VLC_API void input_item_node_Delete( input_item_node_t *p_node );
229 * Option flags
231 enum input_item_option_e
233 /* Allow VLC to trust the given option.
234 * By default options are untrusted */
235 VLC_INPUT_OPTION_TRUSTED = 0x2,
237 /* Add the option, unless the same option
238 * is already present. */
239 VLC_INPUT_OPTION_UNIQUE = 0x100,
243 * This function allows to add an option to an existing input_item_t.
245 VLC_API int input_item_AddOption(input_item_t *, const char *, unsigned i_flags );
247 * This function add several options to an existing input_item_t.
249 VLC_API int input_item_AddOptions(input_item_t *, int i_options,
250 const char *const *ppsz_options,
251 unsigned i_flags );
252 VLC_API int input_item_AddOpaque(input_item_t *, const char *, void *);
254 void input_item_ApplyOptions(vlc_object_t *, input_item_t *);
256 VLC_API bool input_item_slave_GetType(const char *, enum slave_type *);
258 VLC_API input_item_slave_t *input_item_slave_New(const char *, enum slave_type,
259 enum slave_priority);
260 #define input_item_slave_Delete(p_slave) free(p_slave)
263 * This function allows adding a slave to an existing input item.
264 * The slave is owned by the input item after this call.
266 VLC_API int input_item_AddSlave(input_item_t *, input_item_slave_t *);
268 /* */
269 VLC_API bool input_item_HasErrorWhenReading( input_item_t * );
270 VLC_API void input_item_SetMeta( input_item_t *, vlc_meta_type_t meta_type, const char *psz_val );
271 VLC_API bool input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz );
272 VLC_API char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type ) VLC_USED;
273 VLC_API const char *input_item_GetMetaLocked(input_item_t *, vlc_meta_type_t meta_type);
274 VLC_API char * input_item_GetName( input_item_t * p_i ) VLC_USED;
275 VLC_API char * input_item_GetTitleFbName( input_item_t * p_i ) VLC_USED;
276 VLC_API char * input_item_GetURI( input_item_t * p_i ) VLC_USED;
277 VLC_API char * input_item_GetNowPlayingFb( input_item_t *p_item ) VLC_USED;
278 VLC_API void input_item_SetURI( input_item_t * p_i, const char *psz_uri );
279 VLC_API vlc_tick_t input_item_GetDuration( input_item_t * p_i );
280 VLC_API void input_item_SetDuration( input_item_t * p_i, vlc_tick_t i_duration );
281 VLC_API bool input_item_IsPreparsed( input_item_t *p_i );
282 VLC_API bool input_item_IsArtFetched( input_item_t *p_i );
284 #define INPUT_META( name ) \
285 static inline \
286 void input_item_Set ## name (input_item_t *p_input, const char *val) \
288 input_item_SetMeta (p_input, vlc_meta_ ## name, val); \
290 static inline \
291 char *input_item_Get ## name (input_item_t *p_input) \
293 return input_item_GetMeta (p_input, vlc_meta_ ## name); \
296 INPUT_META(Title)
297 INPUT_META(Artist)
298 INPUT_META(AlbumArtist)
299 INPUT_META(Genre)
300 INPUT_META(Copyright)
301 INPUT_META(Album)
302 INPUT_META(TrackNumber)
303 INPUT_META(Description)
304 INPUT_META(Rating)
305 INPUT_META(Date)
306 INPUT_META(Setting)
307 INPUT_META(URL)
308 INPUT_META(Language)
309 INPUT_META(NowPlaying)
310 INPUT_META(ESNowPlaying)
311 INPUT_META(Publisher)
312 INPUT_META(EncodedBy)
313 INPUT_META(ArtworkURL)
314 INPUT_META(TrackID)
315 INPUT_META(TrackTotal)
316 INPUT_META(Director)
317 INPUT_META(Season)
318 INPUT_META(Episode)
319 INPUT_META(ShowName)
320 INPUT_META(Actors)
321 INPUT_META(DiscNumber)
322 INPUT_META(DiscTotal)
324 #define input_item_SetTrackNum input_item_SetTrackNumber
325 #define input_item_GetTrackNum input_item_GetTrackNumber
326 #define input_item_SetArtURL input_item_SetArtworkURL
327 #define input_item_GetArtURL input_item_GetArtworkURL
329 VLC_API char * input_item_GetInfo( input_item_t *p_i, const char *psz_cat,const char *psz_name ) VLC_USED;
330 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 );
331 VLC_API int input_item_DelInfo( input_item_t *p_i, const char *psz_cat, const char *psz_name );
332 VLC_API void input_item_ReplaceInfos( input_item_t *, info_category_t * );
333 VLC_API void input_item_MergeInfos( input_item_t *, info_category_t * );
336 * This function creates a new input_item_t with the provided information.
338 * XXX You may also use input_item_New, as they need less arguments.
340 VLC_API input_item_t * input_item_NewExt( const char *psz_uri,
341 const char *psz_name,
342 vlc_tick_t i_duration, enum input_item_type_e i_type,
343 enum input_item_net_type i_net ) VLC_USED;
345 #define input_item_New( psz_uri, psz_name ) \
346 input_item_NewExt( psz_uri, psz_name, INPUT_DURATION_UNSET, ITEM_TYPE_UNKNOWN, ITEM_NET_UNKNOWN )
348 #define input_item_NewCard( psz_uri, psz_name ) \
349 input_item_NewExt( psz_uri, psz_name, INPUT_DURATION_INDEFINITE, ITEM_TYPE_CARD, ITEM_LOCAL )
351 #define input_item_NewDisc( psz_uri, psz_name, i_duration ) \
352 input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_DISC, ITEM_LOCAL )
354 #define input_item_NewStream( psz_uri, psz_name, i_duration ) \
355 input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_STREAM, ITEM_NET )
357 #define input_item_NewDirectory( psz_uri, psz_name, i_net ) \
358 input_item_NewExt( psz_uri, psz_name, INPUT_DURATION_UNSET, ITEM_TYPE_DIRECTORY, i_net )
360 #define input_item_NewFile( psz_uri, psz_name, i_duration, i_net ) \
361 input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_FILE, i_net )
364 * This function creates a new input_item_t as a copy of another.
366 VLC_API input_item_t * input_item_Copy(input_item_t * ) VLC_USED;
368 /** Holds an input item, i.e. creates a new reference. */
369 VLC_API input_item_t *input_item_Hold(input_item_t *);
371 /** Releases an input item, i.e. decrements its reference counter. */
372 VLC_API void input_item_Release(input_item_t *);
375 * Record prefix string.
376 * TODO make it configurable.
378 #define INPUT_RECORD_PREFIX "vlc-record-%Y-%m-%d-%Hh%Mm%Ss-$ N-$ p"
381 * This function creates a sane filename path.
383 VLC_API char * input_item_CreateFilename( input_item_t *,
384 const char *psz_path, const char *psz_prefix,
385 const char *psz_extension ) VLC_USED;
388 * input item parser opaque structure
390 typedef struct input_item_parser_id_t input_item_parser_id_t;
393 * input item parser callbacks
395 typedef struct input_item_parser_cbs_t
398 * Event received when the parser ends
400 * @note This callback is mandatory.
402 * @param item the parsed item
403 * @param status VLC_SUCCESS in case of success, an error otherwise
404 * @param userdata user data set by input_item_Parse()
406 void (*on_ended)(input_item_t *item, int status, void *userdata);
409 * Event received when a new subtree is added
411 * @note This callback is optional.
413 * @param item the parsed item
414 * @param subtree sub items of the current item
415 * @param userdata user data set by input_item_Parse()
417 void (*on_subtree_added)(input_item_t *item, input_item_node_t *subtree, void *userdata);
418 } input_item_parser_cbs_t;
421 * Parse an item asynchronously
423 * @note The parsing is done asynchronously. The user can call
424 * input_item_parser_id_Interrupt() before receiving the on_ended() event in
425 * order to interrupt it.
427 * @param item the item to parse
428 * @param parent the parent obj
429 * @param cbs callbacks to be notified of the end of the parsing
430 * @param userdata opaque data used by parser callbacks
432 * @return a parser instance or NULL in case of error, the parser needs to be
433 * released with input_item_parser_id_Release()
435 VLC_API input_item_parser_id_t *
436 input_item_Parse(input_item_t *item, vlc_object_t *parent,
437 const input_item_parser_cbs_t *cbs, void *userdata) VLC_USED;
440 * Interrupts & cancels the parsing
442 * @note The parser still needs to be released with input_item_parser_id_Release
443 * afterward.
444 * @note Calling this function will cause the on_ended callback to be invoked.
446 * @param the parser to interrupt
448 VLC_API void
449 input_item_parser_id_Interrupt(input_item_parser_id_t *parser);
452 * Release (and interrupt if needed) a parser
454 * @param parser the parser returned by input_item_Parse
456 VLC_API void
457 input_item_parser_id_Release(input_item_parser_id_t *parser);
459 typedef enum input_item_meta_request_option_t
461 META_REQUEST_OPTION_NONE = 0x00,
462 META_REQUEST_OPTION_SCOPE_LOCAL = 0x01,
463 META_REQUEST_OPTION_SCOPE_NETWORK = 0x02,
464 META_REQUEST_OPTION_SCOPE_ANY = 0x03,
465 META_REQUEST_OPTION_FETCH_LOCAL = 0x04,
466 META_REQUEST_OPTION_FETCH_NETWORK = 0x08,
467 META_REQUEST_OPTION_FETCH_ANY = 0x0C,
468 META_REQUEST_OPTION_DO_INTERACT = 0x10,
469 } input_item_meta_request_option_t;
471 /* status of the on_preparse_ended() callback */
472 enum input_item_preparse_status
474 ITEM_PREPARSE_SKIPPED,
475 ITEM_PREPARSE_FAILED,
476 ITEM_PREPARSE_TIMEOUT,
477 ITEM_PREPARSE_DONE
480 typedef struct input_preparser_callbacks_t {
481 void (*on_preparse_ended)(input_item_t *, enum input_item_preparse_status status, void *userdata);
482 void (*on_subtree_added)(input_item_t *, input_item_node_t *subtree, void *userdata);
483 } input_preparser_callbacks_t;
485 typedef struct input_fetcher_callbacks_t {
486 void (*on_art_fetch_ended)(input_item_t *, bool fetched, void *userdata);
487 } input_fetcher_callbacks_t;
489 VLC_API int libvlc_MetadataRequest( libvlc_int_t *, input_item_t *,
490 input_item_meta_request_option_t,
491 const input_preparser_callbacks_t *cbs,
492 void *cbs_userdata,
493 int, void * );
494 VLC_API int libvlc_ArtRequest(libvlc_int_t *, input_item_t *,
495 input_item_meta_request_option_t,
496 const input_fetcher_callbacks_t *cbs,
497 void *cbs_userdata );
498 VLC_API void libvlc_MetadataCancel( libvlc_int_t *, void * );
500 /******************
501 * Input stats
502 ******************/
503 struct input_stats_t
505 /* Input */
506 int64_t i_read_packets;
507 int64_t i_read_bytes;
508 float f_input_bitrate;
510 /* Demux */
511 int64_t i_demux_read_packets;
512 int64_t i_demux_read_bytes;
513 float f_demux_bitrate;
514 int64_t i_demux_corrupted;
515 int64_t i_demux_discontinuity;
517 /* Decoders */
518 int64_t i_decoded_audio;
519 int64_t i_decoded_video;
521 /* Vout */
522 int64_t i_displayed_pictures;
523 int64_t i_lost_pictures;
525 /* Aout */
526 int64_t i_played_abuffers;
527 int64_t i_lost_abuffers;
531 * Access pf_readdir helper struct
532 * \see vlc_readdir_helper_init()
533 * \see vlc_readdir_helper_additem()
534 * \see vlc_readdir_helper_finish()
536 struct vlc_readdir_helper
538 input_item_node_t *p_node;
539 void **pp_slaves;
540 size_t i_slaves;
541 void **pp_dirs;
542 size_t i_dirs;
543 int i_sub_autodetect_fuzzy;
544 bool b_show_hiddenfiles;
545 bool b_flatten;
546 char *psz_ignored_exts;
550 * Init a vlc_readdir_helper struct
552 * \param p_rdh need to be cleaned with vlc_readdir_helper_finish()
553 * \param p_node node that will be used to add items
555 VLC_API void vlc_readdir_helper_init(struct vlc_readdir_helper *p_rdh,
556 vlc_object_t *p_obj, input_item_node_t *p_node);
557 #define vlc_readdir_helper_init(p_rdh, p_obj, p_node) \
558 vlc_readdir_helper_init(p_rdh, VLC_OBJECT(p_obj), p_node)
561 * Finish adding items to the node
563 * \param b_success if true, items of the node will be sorted.
565 VLC_API void vlc_readdir_helper_finish(struct vlc_readdir_helper *p_rdh, bool b_success);
568 * Add a new input_item_t entry to the node of the vlc_readdir_helper struct.
570 * \param p_rdh previously inited vlc_readdir_helper struct
571 * \param psz_uri uri of the new item
572 * \param psz_flatpath flattened path of the new item. If not NULL, this
573 * function will create an input item for each sub folders (separated
574 * by '/') of psz_flatpath (so, this will un-flatten the folder
575 * hierarchy). Either psz_flatpath or psz_filename must be valid.
576 * \param psz_filename file name of the new item. If NULL, the file part of path
577 * will be used as a filename. Either psz_flatpath or psz_filename must
578 * be valid.
579 * \param i_type see \ref input_item_type_e
580 * \param i_net see \ref input_item_net_type
582 VLC_API int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
583 const char *psz_uri, const char *psz_flatpath,
584 const char *psz_filename,
585 int i_type, int i_net);
587 #endif