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
29 * This file defines functions, structures and enums for input items in vlc
34 #include <vlc_events.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
;
45 char *psz_name
; /**< Name of this info */
46 char *psz_value
; /**< Value of the info */
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
69 /* This one is not a real type but the number of input_item types. */
74 * Describes an input and is used to spawn input_thread_t objects.
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 */
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 */
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
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
124 void *libvlc_owner
; /**< LibVLC private data, can only be set
125 before events are registered. */
128 #define INPUT_ITEM_URI_NOP "vlc://nop" /* dummy URI for node/directory items */
130 /* placeholder duration for items with no known duration at time of creation
131 * it may remain the duration for items like a node/directory */
132 #define INPUT_DURATION_UNSET VLC_TICK_INVALID
133 #define INPUT_DURATION_INDEFINITE (-1) /* item with a known indefinite duration (live/continuous source) */
135 enum input_item_net_type
150 SLAVE_PRIORITY_MATCH_NONE
= 1,
151 SLAVE_PRIORITY_MATCH_RIGHT
,
152 SLAVE_PRIORITY_MATCH_LEFT
,
153 SLAVE_PRIORITY_MATCH_ALL
,
157 /* Extensions must be in alphabetical order */
158 #define MASTER_EXTENSIONS \
159 "asf", "avi", "divx", \
160 "f4v", "flv", "m1v", \
161 "m2v", "m4v", "mkv", \
162 "mov", "mp2", "mp2v", \
163 "mp4", "mp4v", "mpe", \
164 "mpeg", "mpeg1", "mpeg2", \
165 "mpeg4", "mpg", "mpv2", \
166 "mxf", "ogv", "ogx", \
167 "ps", "vro","webm", \
170 #define SLAVE_SPU_EXTENSIONS \
171 "aqt", "ass", "cdg", \
172 "dks", "idx", "jss", \
173 "mpl2", "mpsub", "pjs", \
174 "psb", "rt", "sami", "sbv", \
175 "scc", "smi", "srt", \
176 "ssa", "stl", "sub", \
177 "tt", "ttml", "usf", \
180 #define SLAVE_AUDIO_EXTENSIONS \
181 "aac", "ac3", "dts", \
182 "dtshd", "eac3", "flac", \
183 "m4a", "mp3", "pcm" \
185 struct input_item_slave
187 enum slave_type i_type
; /**< Slave type (spu, audio) */
188 enum slave_priority i_priority
; /**< Slave priority */
189 bool b_forced
; /**< Slave should be selected */
190 char psz_uri
[]; /**< Slave mrl */
193 struct input_item_node_t
195 input_item_t
* p_item
;
197 input_item_node_t
**pp_children
;
200 VLC_API
void input_item_CopyOptions( input_item_t
*p_child
, input_item_t
*p_parent
);
201 VLC_API
void input_item_SetName( input_item_t
*p_item
, const char *psz_name
);
204 * Start adding multiple subitems.
206 * Create a root node to hold a tree of subitems for given item
208 VLC_API input_item_node_t
* input_item_node_Create( input_item_t
*p_input
) VLC_USED
;
211 * Add a new child node to this parent node that will point to this subitem.
213 VLC_API input_item_node_t
* input_item_node_AppendItem( input_item_node_t
*p_node
, input_item_t
*p_item
);
216 * Add an already created node to children of this parent node.
218 VLC_API
void input_item_node_AppendNode( input_item_node_t
*p_parent
, input_item_node_t
*p_child
);
221 * Remove a node from its parent.
223 VLC_API
void input_item_node_RemoveNode( input_item_node_t
*parent
,
224 input_item_node_t
*child
);
227 * Delete a node created with input_item_node_Create() and all its children.
229 VLC_API
void input_item_node_Delete( input_item_node_t
*p_node
);
234 enum input_item_option_e
236 /* Allow VLC to trust the given option.
237 * By default options are untrusted */
238 VLC_INPUT_OPTION_TRUSTED
= 0x2,
240 /* Add the option, unless the same option
241 * is already present. */
242 VLC_INPUT_OPTION_UNIQUE
= 0x100,
246 * This function allows to add an option to an existing input_item_t.
248 VLC_API
int input_item_AddOption(input_item_t
*, const char *, unsigned i_flags
);
250 * This function add several options to an existing input_item_t.
252 VLC_API
int input_item_AddOptions(input_item_t
*, int i_options
,
253 const char *const *ppsz_options
,
255 VLC_API
int input_item_AddOpaque(input_item_t
*, const char *, void *);
257 void input_item_ApplyOptions(vlc_object_t
*, input_item_t
*);
259 VLC_API
bool input_item_slave_GetType(const char *, enum slave_type
*);
261 VLC_API input_item_slave_t
*input_item_slave_New(const char *, enum slave_type
,
262 enum slave_priority
);
263 #define input_item_slave_Delete(p_slave) free(p_slave)
266 * This function allows adding a slave to an existing input item.
267 * The slave is owned by the input item after this call.
269 VLC_API
int input_item_AddSlave(input_item_t
*, input_item_slave_t
*);
272 VLC_API
bool input_item_HasErrorWhenReading( input_item_t
* );
273 VLC_API
void input_item_SetMeta( input_item_t
*, vlc_meta_type_t meta_type
, const char *psz_val
);
274 VLC_API
bool input_item_MetaMatch( input_item_t
*p_i
, vlc_meta_type_t meta_type
, const char *psz
);
275 VLC_API
char * input_item_GetMeta( input_item_t
*p_i
, vlc_meta_type_t meta_type
) VLC_USED
;
276 VLC_API
const char *input_item_GetMetaLocked(input_item_t
*, vlc_meta_type_t meta_type
);
277 VLC_API
char * input_item_GetName( input_item_t
* p_i
) VLC_USED
;
278 VLC_API
char * input_item_GetTitleFbName( input_item_t
* p_i
) VLC_USED
;
279 VLC_API
char * input_item_GetURI( input_item_t
* p_i
) VLC_USED
;
280 VLC_API
char * input_item_GetNowPlayingFb( input_item_t
*p_item
) VLC_USED
;
281 VLC_API
void input_item_SetURI( input_item_t
* p_i
, const char *psz_uri
);
282 VLC_API vlc_tick_t
input_item_GetDuration( input_item_t
* p_i
);
283 VLC_API
void input_item_SetDuration( input_item_t
* p_i
, vlc_tick_t i_duration
);
284 VLC_API
bool input_item_IsPreparsed( input_item_t
*p_i
);
285 VLC_API
bool input_item_IsArtFetched( input_item_t
*p_i
);
287 #define INPUT_META( name ) \
289 void input_item_Set ## name (input_item_t *p_input, const char *val) \
291 input_item_SetMeta (p_input, vlc_meta_ ## name, val); \
294 char *input_item_Get ## name (input_item_t *p_input) \
296 return input_item_GetMeta (p_input, vlc_meta_ ## name); \
301 INPUT_META(AlbumArtist
)
303 INPUT_META(Copyright
)
305 INPUT_META(TrackNumber
)
306 INPUT_META(Description
)
312 INPUT_META(NowPlaying
)
313 INPUT_META(ESNowPlaying
)
314 INPUT_META(Publisher
)
315 INPUT_META(EncodedBy
)
316 INPUT_META(ArtworkURL
)
318 INPUT_META(TrackTotal
)
324 INPUT_META(DiscNumber
)
325 INPUT_META(DiscTotal
)
327 #define input_item_SetTrackNum input_item_SetTrackNumber
328 #define input_item_GetTrackNum input_item_GetTrackNumber
329 #define input_item_SetArtURL input_item_SetArtworkURL
330 #define input_item_GetArtURL input_item_GetArtworkURL
332 VLC_API
char * input_item_GetInfo( input_item_t
*p_i
, const char *psz_cat
,const char *psz_name
) VLC_USED
;
333 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 );
334 VLC_API
int input_item_DelInfo( input_item_t
*p_i
, const char *psz_cat
, const char *psz_name
);
335 VLC_API
void input_item_ReplaceInfos( input_item_t
*, info_category_t
* );
336 VLC_API
void input_item_MergeInfos( input_item_t
*, info_category_t
* );
339 * This function creates a new input_item_t with the provided information.
341 * XXX You may also use input_item_New, as they need less arguments.
343 VLC_API input_item_t
* input_item_NewExt( const char *psz_uri
,
344 const char *psz_name
,
345 vlc_tick_t i_duration
, enum input_item_type_e i_type
,
346 enum input_item_net_type i_net
) VLC_USED
;
348 #define input_item_New( psz_uri, psz_name ) \
349 input_item_NewExt( psz_uri, psz_name, INPUT_DURATION_UNSET, ITEM_TYPE_UNKNOWN, ITEM_NET_UNKNOWN )
351 #define input_item_NewCard( psz_uri, psz_name ) \
352 input_item_NewExt( psz_uri, psz_name, INPUT_DURATION_INDEFINITE, ITEM_TYPE_CARD, ITEM_LOCAL )
354 #define input_item_NewDisc( psz_uri, psz_name, i_duration ) \
355 input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_DISC, ITEM_LOCAL )
357 #define input_item_NewStream( psz_uri, psz_name, i_duration ) \
358 input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_STREAM, ITEM_NET )
360 #define input_item_NewDirectory( psz_uri, psz_name, i_net ) \
361 input_item_NewExt( psz_uri, psz_name, INPUT_DURATION_UNSET, ITEM_TYPE_DIRECTORY, i_net )
363 #define input_item_NewFile( psz_uri, psz_name, i_duration, i_net ) \
364 input_item_NewExt( psz_uri, psz_name, i_duration, ITEM_TYPE_FILE, i_net )
367 * This function creates a new input_item_t as a copy of another.
369 VLC_API input_item_t
* input_item_Copy(input_item_t
* ) VLC_USED
;
371 /** Holds an input item, i.e. creates a new reference. */
372 VLC_API input_item_t
*input_item_Hold(input_item_t
*);
374 /** Releases an input item, i.e. decrements its reference counter. */
375 VLC_API
void input_item_Release(input_item_t
*);
378 * Record prefix string.
379 * TODO make it configurable.
381 #define INPUT_RECORD_PREFIX "vlc-record-%Y-%m-%d-%Hh%Mm%Ss-$ N-$ p"
384 * This function creates a sane filename path.
386 VLC_API
char * input_item_CreateFilename( input_item_t
*,
387 const char *psz_path
, const char *psz_prefix
,
388 const char *psz_extension
) VLC_USED
;
391 * input item parser opaque structure
393 typedef struct input_item_parser_id_t input_item_parser_id_t
;
396 * input item parser callbacks
398 typedef struct input_item_parser_cbs_t
401 * Event received when the parser ends
403 * @note This callback is mandatory.
405 * @param item the parsed item
406 * @param status VLC_SUCCESS in case of success, an error otherwise
407 * @param userdata user data set by input_item_Parse()
409 void (*on_ended
)(input_item_t
*item
, int status
, void *userdata
);
412 * Event received when a new subtree is added
414 * @note This callback is optional.
416 * @param item the parsed item
417 * @param subtree sub items of the current item
418 * @param userdata user data set by input_item_Parse()
420 void (*on_subtree_added
)(input_item_t
*item
, input_item_node_t
*subtree
, void *userdata
);
421 } input_item_parser_cbs_t
;
424 * Parse an item asynchronously
426 * @note The parsing is done asynchronously. The user can call
427 * input_item_parser_id_Interrupt() before receiving the on_ended() event in
428 * order to interrupt it.
430 * @param item the item to parse
431 * @param parent the parent obj
432 * @param cbs callbacks to be notified of the end of the parsing
433 * @param userdata opaque data used by parser callbacks
435 * @return a parser instance or NULL in case of error, the parser needs to be
436 * released with input_item_parser_id_Release()
438 VLC_API input_item_parser_id_t
*
439 input_item_Parse(input_item_t
*item
, vlc_object_t
*parent
,
440 const input_item_parser_cbs_t
*cbs
, void *userdata
) VLC_USED
;
443 * Interrupts & cancels the parsing
445 * @note The parser still needs to be released with input_item_parser_id_Release
447 * @note Calling this function will cause the on_ended callback to be invoked.
449 * @param the parser to interrupt
452 input_item_parser_id_Interrupt(input_item_parser_id_t
*parser
);
455 * Release (and interrupt if needed) a parser
457 * @param parser the parser returned by input_item_Parse
460 input_item_parser_id_Release(input_item_parser_id_t
*parser
);
462 typedef enum input_item_meta_request_option_t
464 META_REQUEST_OPTION_NONE
= 0x00,
465 META_REQUEST_OPTION_SCOPE_LOCAL
= 0x01,
466 META_REQUEST_OPTION_SCOPE_NETWORK
= 0x02,
467 META_REQUEST_OPTION_SCOPE_ANY
= 0x03,
468 META_REQUEST_OPTION_FETCH_LOCAL
= 0x04,
469 META_REQUEST_OPTION_FETCH_NETWORK
= 0x08,
470 META_REQUEST_OPTION_FETCH_ANY
= 0x0C,
471 META_REQUEST_OPTION_DO_INTERACT
= 0x10,
472 } input_item_meta_request_option_t
;
474 /* status of the on_preparse_ended() callback */
475 enum input_item_preparse_status
477 ITEM_PREPARSE_SKIPPED
,
478 ITEM_PREPARSE_FAILED
,
479 ITEM_PREPARSE_TIMEOUT
,
483 typedef struct input_preparser_callbacks_t
{
484 void (*on_preparse_ended
)(input_item_t
*, enum input_item_preparse_status status
, void *userdata
);
485 void (*on_subtree_added
)(input_item_t
*, input_item_node_t
*subtree
, void *userdata
);
486 } input_preparser_callbacks_t
;
488 typedef struct input_fetcher_callbacks_t
{
489 void (*on_art_fetch_ended
)(input_item_t
*, bool fetched
, void *userdata
);
490 } input_fetcher_callbacks_t
;
492 VLC_API
int libvlc_MetadataRequest( libvlc_int_t
*, input_item_t
*,
493 input_item_meta_request_option_t
,
494 const input_preparser_callbacks_t
*cbs
,
497 VLC_API
int libvlc_ArtRequest(libvlc_int_t
*, input_item_t
*,
498 input_item_meta_request_option_t
,
499 const input_fetcher_callbacks_t
*cbs
,
500 void *cbs_userdata
);
501 VLC_API
void libvlc_MetadataCancel( libvlc_int_t
*, void * );
509 int64_t i_read_packets
;
510 int64_t i_read_bytes
;
511 float f_input_bitrate
;
514 int64_t i_demux_read_packets
;
515 int64_t i_demux_read_bytes
;
516 float f_demux_bitrate
;
517 int64_t i_demux_corrupted
;
518 int64_t i_demux_discontinuity
;
521 int64_t i_decoded_audio
;
522 int64_t i_decoded_video
;
525 int64_t i_displayed_pictures
;
526 int64_t i_late_pictures
;
527 int64_t i_lost_pictures
;
530 int64_t i_played_abuffers
;
531 int64_t i_lost_abuffers
;
535 * Access pf_readdir helper struct
536 * \see vlc_readdir_helper_init()
537 * \see vlc_readdir_helper_additem()
538 * \see vlc_readdir_helper_finish()
540 struct vlc_readdir_helper
542 input_item_node_t
*p_node
;
547 int i_sub_autodetect_fuzzy
;
548 bool b_show_hiddenfiles
;
550 char *psz_ignored_exts
;
554 * Init a vlc_readdir_helper struct
556 * \param p_rdh need to be cleaned with vlc_readdir_helper_finish()
557 * \param p_node node that will be used to add items
559 VLC_API
void vlc_readdir_helper_init(struct vlc_readdir_helper
*p_rdh
,
560 vlc_object_t
*p_obj
, input_item_node_t
*p_node
);
561 #define vlc_readdir_helper_init(p_rdh, p_obj, p_node) \
562 vlc_readdir_helper_init(p_rdh, VLC_OBJECT(p_obj), p_node)
565 * Finish adding items to the node
567 * \param b_success if true, items of the node will be sorted.
569 VLC_API
void vlc_readdir_helper_finish(struct vlc_readdir_helper
*p_rdh
, bool b_success
);
572 * Add a new input_item_t entry to the node of the vlc_readdir_helper struct.
574 * \param p_rdh previously inited vlc_readdir_helper struct
575 * \param psz_uri uri of the new item
576 * \param psz_flatpath flattened path of the new item. If not NULL, this
577 * function will create an input item for each sub folders (separated
578 * by '/') of psz_flatpath (so, this will un-flatten the folder
579 * hierarchy). Either psz_flatpath or psz_filename must be valid.
580 * \param psz_filename file name of the new item. If NULL, the file part of path
581 * will be used as a filename. Either psz_flatpath or psz_filename must
583 * \param i_type see \ref input_item_type_e
584 * \param i_net see \ref input_item_net_type
586 VLC_API
int vlc_readdir_helper_additem(struct vlc_readdir_helper
*p_rdh
,
587 const char *psz_uri
, const char *psz_flatpath
,
588 const char *psz_filename
,
589 int i_type
, int i_net
);