1 /*****************************************************************************
2 * vlc_input_item.h: Core input item
3 *****************************************************************************
4 * Copyright (C) 1999-2009 VLC authors and VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
25 #ifndef VLC_INPUT_ITEM_H
26 #define VLC_INPUT_ITEM_H 1
30 * This file defines functions, structures and enums for input items in vlc
35 #include <vlc_events.h>
40 typedef struct input_item_opaque input_item_opaque_t
;
41 typedef struct input_item_slave input_item_slave_t
;
42 typedef struct input_preparser_callbacks_t input_preparser_callbacks_t
;
46 char *psz_name
; /**< Name of this info */
47 char *psz_value
; /**< Value of the info */
51 #define info_foreach(info, cat) vlc_list_foreach(info, cat, node)
53 struct info_category_t
55 char *psz_name
; /**< Name of this category */
56 struct vlc_list infos
; /**< Infos in the category */
59 enum input_item_type_e
70 /* This one is not a real type but the number of input_item types. */
75 * Describes an input and is used to spawn input_thread_t objects.
79 char *psz_name
; /**< text describing this item */
80 char *psz_uri
; /**< mrl of this item */
82 int i_options
; /**< Number of input options */
83 char **ppsz_options
; /**< Array of input options */
84 uint8_t *optflagv
; /**< Some flags of input options */
86 input_item_opaque_t
*opaques
; /**< List of opaque pointer values */
88 vlc_tick_t i_duration
; /**< Duration in microseconds */
91 int i_categories
; /**< Number of info categories */
92 info_category_t
**pp_categories
; /**< Pointer to the first info category */
94 int i_es
; /**< Number of es format descriptions */
95 es_format_t
**es
; /**< Es formats */
97 input_stats_t
*p_stats
; /**< Statistics */
101 int i_epg
; /**< Number of EPG entries */
102 vlc_epg_t
**pp_epg
; /**< EPG entries */
103 int64_t i_epg_time
; /** EPG timedate as epoch time */
104 const vlc_epg_t
*p_epg_table
; /** running/selected program cur/next EPG table */
106 int i_slaves
; /**< Number of slaves */
107 input_item_slave_t
**pp_slaves
; /**< Slave entries that will be loaded by
110 vlc_event_manager_t event_manager
;
112 vlc_mutex_t lock
; /**< Lock for the item */
114 enum input_item_type_e i_type
; /**< Type (file, disc, ... see input_item_type_e) */
115 bool b_net
; /**< Net: always true for TYPE_STREAM, it
116 depends for others types */
117 bool b_error_when_reading
;/**< Error When Reading */
119 int i_preparse_depth
; /**< How many level of sub items can be preparsed:
120 -1: recursive, 0: none, >0: n levels */
122 bool b_preparse_interact
; /**< Force interaction with the user when
126 #define INPUT_ITEM_URI_NOP "vlc://nop" /* dummy URI for node/directory items */
128 /* placeholder duration for items with no known duration at time of creation
129 * it may remain the duration for items like a node/directory */
130 #define INPUT_DURATION_UNSET VLC_TICK_INVALID
131 #define INPUT_DURATION_INDEFINITE (-1) /* item with a known indefinite duration (live/continuous source) */
133 enum input_item_net_type
148 SLAVE_PRIORITY_MATCH_NONE
= 1,
149 SLAVE_PRIORITY_MATCH_RIGHT
,
150 SLAVE_PRIORITY_MATCH_LEFT
,
151 SLAVE_PRIORITY_MATCH_ALL
,
155 /* Extensions must be in alphabetical order */
156 #define MASTER_EXTENSIONS \
157 "asf", "avi", "divx", \
158 "f4v", "flv", "m1v", \
159 "m2v", "m4v", "mkv", \
160 "mov", "mp2", "mp2v", \
161 "mp4", "mp4v", "mpe", \
162 "mpeg", "mpeg1", "mpeg2", \
163 "mpeg4", "mpg", "mpv2", \
164 "mxf", "ogv", "ogx", \
165 "ps", "vro","webm", \
168 #define SLAVE_SPU_EXTENSIONS \
169 "aqt", "ass", "cdg", \
170 "dks", "idx", "jss", \
171 "mpl2", "mpsub", "pjs", \
172 "psb", "rt", "sami", "sbv", \
173 "scc", "smi", "srt", \
174 "ssa", "stl", "sub", \
175 "ttml", "tt", "usf", \
178 #define SLAVE_AUDIO_EXTENSIONS \
179 "aac", "ac3", "dts", \
180 "dtshd", "eac3", "flac", \
181 "m4a", "mp3", "pcm" \
183 struct input_item_slave
185 enum slave_type i_type
; /**< Slave type (spu, audio) */
186 enum slave_priority i_priority
; /**< Slave priority */
187 bool b_forced
; /**< Slave should be selected */
188 char psz_uri
[]; /**< Slave mrl */
191 struct input_item_node_t
193 input_item_t
* p_item
;
195 input_item_node_t
**pp_children
;
198 VLC_API
void input_item_CopyOptions( input_item_t
*p_child
, input_item_t
*p_parent
);
199 VLC_API
void input_item_SetName( input_item_t
*p_item
, const char *psz_name
);
202 * Start adding multiple subitems.
204 * Create a root node to hold a tree of subitems for given item
206 VLC_API input_item_node_t
* input_item_node_Create( input_item_t
*p_input
) VLC_USED
;
209 * Add a new child node to this parent node that will point to this subitem.
211 VLC_API input_item_node_t
* input_item_node_AppendItem( input_item_node_t
*p_node
, input_item_t
*p_item
);
214 * Add an already created node to children of this parent node.
216 VLC_API
void input_item_node_AppendNode( input_item_node_t
*p_parent
, input_item_node_t
*p_child
);
219 * Remove a node from its parent.
221 void input_item_node_RemoveNode( input_item_node_t
*parent
,
222 input_item_node_t
*child
);
225 * Delete a node created with input_item_node_Create() and all its children.
227 VLC_API
void input_item_node_Delete( input_item_node_t
*p_node
);
232 enum input_item_option_e
234 /* Allow VLC to trust the given option.
235 * By default options are untrusted */
236 VLC_INPUT_OPTION_TRUSTED
= 0x2,
238 /* Add the option, unless the same option
239 * is already present. */
240 VLC_INPUT_OPTION_UNIQUE
= 0x100,
244 * This function allows to add an option to an existing input_item_t.
246 VLC_API
int input_item_AddOption(input_item_t
*, const char *, unsigned i_flags
);
248 * This function add several options to an existing input_item_t.
250 VLC_API
int input_item_AddOptions(input_item_t
*, int i_options
,
251 const char *const *ppsz_options
,
253 VLC_API
int input_item_AddOpaque(input_item_t
*, const char *, void *);
255 void input_item_ApplyOptions(vlc_object_t
*, input_item_t
*);
257 VLC_API
bool input_item_slave_GetType(const char *, enum slave_type
*);
259 VLC_API input_item_slave_t
*input_item_slave_New(const char *, enum slave_type
,
260 enum slave_priority
);
261 #define input_item_slave_Delete(p_slave) free(p_slave)
264 * This function allows adding a slave to an existing input item.
265 * The slave is owned by the input item after this call.
267 VLC_API
int input_item_AddSlave(input_item_t
*, input_item_slave_t
*);
270 VLC_API
bool input_item_HasErrorWhenReading( input_item_t
* );
271 VLC_API
void input_item_SetMeta( input_item_t
*, vlc_meta_type_t meta_type
, const char *psz_val
);
272 VLC_API
bool input_item_MetaMatch( input_item_t
*p_i
, vlc_meta_type_t meta_type
, const char *psz
);
273 VLC_API
char * input_item_GetMeta( input_item_t
*p_i
, vlc_meta_type_t meta_type
) VLC_USED
;
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 ) \
286 void input_item_Set ## name (input_item_t *p_input, const char *val) \
288 input_item_SetMeta (p_input, vlc_meta_ ## name, val); \
291 char *input_item_Get ## name (input_item_t *p_input) \
293 return input_item_GetMeta (p_input, vlc_meta_ ## name); \
298 INPUT_META(AlbumArtist
)
300 INPUT_META(Copyright
)
302 INPUT_META(TrackNumber
)
303 INPUT_META(Description
)
309 INPUT_META(NowPlaying
)
310 INPUT_META(ESNowPlaying
)
311 INPUT_META(Publisher
)
312 INPUT_META(EncodedBy
)
313 INPUT_META(ArtworkURL
)
315 INPUT_META(TrackTotal
)
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
*);
374 typedef enum input_item_meta_request_option_t
376 META_REQUEST_OPTION_NONE
= 0x00,
377 META_REQUEST_OPTION_SCOPE_LOCAL
= 0x01,
378 META_REQUEST_OPTION_SCOPE_NETWORK
= 0x02,
379 META_REQUEST_OPTION_SCOPE_ANY
= 0x03,
380 META_REQUEST_OPTION_DO_INTERACT
= 0x04
381 } input_item_meta_request_option_t
;
383 /* status of the on_preparse_ended() callback */
384 enum input_item_preparse_status
386 ITEM_PREPARSE_SKIPPED
,
387 ITEM_PREPARSE_FAILED
,
388 ITEM_PREPARSE_TIMEOUT
,
392 typedef struct input_preparser_callbacks_t
{
393 void (*on_preparse_ended
)(input_item_t
*, enum input_item_preparse_status status
, void *userdata
);
394 void (*on_subtree_added
)(input_item_t
*, input_item_node_t
*subtree
, void *userdata
);
395 } input_preparser_callbacks_t
;
397 typedef struct input_fetcher_callbacks_t
{
398 void (*on_art_fetch_ended
)(input_item_t
*, bool fetched
, void *userdata
);
399 } input_fetcher_callbacks_t
;
401 VLC_API
int libvlc_MetadataRequest( libvlc_int_t
*, input_item_t
*,
402 input_item_meta_request_option_t
,
403 const input_preparser_callbacks_t
*cbs
,
406 VLC_API
int libvlc_ArtRequest(libvlc_int_t
*, input_item_t
*,
407 input_item_meta_request_option_t
,
408 const input_fetcher_callbacks_t
*cbs
,
409 void *cbs_userdata
);
410 VLC_API
void libvlc_MetadataCancel( libvlc_int_t
*, void * );
418 int64_t i_read_packets
;
419 int64_t i_read_bytes
;
420 float f_input_bitrate
;
423 int64_t i_demux_read_packets
;
424 int64_t i_demux_read_bytes
;
425 float f_demux_bitrate
;
426 int64_t i_demux_corrupted
;
427 int64_t i_demux_discontinuity
;
430 int64_t i_decoded_audio
;
431 int64_t i_decoded_video
;
434 int64_t i_displayed_pictures
;
435 int64_t i_lost_pictures
;
438 int64_t i_played_abuffers
;
439 int64_t i_lost_abuffers
;
443 * Access pf_readdir helper struct
444 * \see vlc_readdir_helper_init()
445 * \see vlc_readdir_helper_additem()
446 * \see vlc_readdir_helper_finish()
448 struct vlc_readdir_helper
450 input_item_node_t
*p_node
;
455 int i_sub_autodetect_fuzzy
;
456 bool b_show_hiddenfiles
;
458 char *psz_ignored_exts
;
462 * Init a vlc_readdir_helper struct
464 * \param p_rdh need to be cleaned with vlc_readdir_helper_finish()
465 * \param p_node node that will be used to add items
467 VLC_API
void vlc_readdir_helper_init(struct vlc_readdir_helper
*p_rdh
,
468 vlc_object_t
*p_obj
, input_item_node_t
*p_node
);
469 #define vlc_readdir_helper_init(p_rdh, p_obj, p_node) \
470 vlc_readdir_helper_init(p_rdh, VLC_OBJECT(p_obj), p_node)
473 * Finish adding items to the node
475 * \param b_success if true, items of the node will be sorted.
477 VLC_API
void vlc_readdir_helper_finish(struct vlc_readdir_helper
*p_rdh
, bool b_success
);
480 * Add a new input_item_t entry to the node of the vlc_readdir_helper struct.
482 * \param p_rdh previously inited vlc_readdir_helper struct
483 * \param psz_uri uri of the new item
484 * \param psz_flatpath flattened path of the new item. If not NULL, this
485 * function will create an input item for each sub folders (separated
486 * by '/') of psz_flatpath (so, this will un-flatten the folder
487 * hierarchy). Either psz_flatpath or psz_filename must be valid.
488 * \param psz_filename file name of the new item. If NULL, the file part of path
489 * will be used as a filename. Either psz_flatpath or psz_filename must
491 * \param i_type see \ref input_item_type_e
492 * \param i_net see \ref input_item_net_type
494 VLC_API
int vlc_readdir_helper_additem(struct vlc_readdir_helper
*p_rdh
,
495 const char *psz_uri
, const char *psz_flatpath
,
496 const char *psz_filename
,
497 int i_type
, int i_net
);