1 /*****************************************************************************
2 * vlc_playlist.h : Playlist functions
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef _VLC_PLAYLIST_H_
25 #define _VLC_PLAYLIST_H_
29 * This file contain structures and function prototypes related
30 * to the playlist in vlc
34 * \defgroup vlc_playlist Playlist
35 * Brief description. Longer description
40 * playlist export helper structure
42 struct playlist_export_t
46 playlist_item_t *p_root;
50 * playlist item / node
53 struct playlist_item_t
55 input_item_t *p_input; /**< input item descriptor */
57 /* Tree specific fields */
58 int i_children; /**< Number of children
60 playlist_item_t **pp_children; /**< Children nodes/items */
61 playlist_item_t *p_parent; /**< Item parent */
63 int i_id; /**< Playlist item specific id */
65 uint8_t i_flags; /**< Flags */
68 #define PLAYLIST_SAVE_FLAG 0x0001 /**< Must it be saved */
69 #define PLAYLIST_SKIP_FLAG 0x0002 /**< Must playlist skip after it ? */
70 #define PLAYLIST_DBL_FLAG 0x0004 /**< Is it disabled ? */
71 #define PLAYLIST_RO_FLAG 0x0008 /**< Write-enabled ? */
72 #define PLAYLIST_REMOVE_FLAG 0x0010 /**< Remove this item at the end */
73 #define PLAYLIST_EXPANDED_FLAG 0x0020 /**< Expanded node */
74 #define PLAYLIST_PREFCAT_FLAG 0x0040 /**< Prefer category */
80 { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
83 struct services_discovery_t
90 services_discovery_sys_t *p_sys;
91 void (*pf_run) ( services_discovery_t *);
94 struct playlist_preparse_t
99 input_item_t **pp_waiting;
103 /** Structure containing information about the playlist */
109 These members are uniq to playlist_t
112 int i_enabled; /**< How many items are enabled ? */
114 /* Arrays of items */
115 int i_size; /**< total size of the list */
116 playlist_item_t ** pp_items; /**< array of pointers to the
118 int i_all_size; /**< size of list of items and nodes */
119 playlist_item_t ** pp_all_items; /**< array of pointers to the
120 * playlist items and nodes */
122 input_item_t ** pp_input_items;
124 int i_last_playlist_id; /**< Last id to an item */
125 int i_last_input_id ; /**< Last id on an input */
127 services_discovery_t **pp_sds;
130 /* Predefined items */
131 playlist_item_t * p_root_category;
132 playlist_item_t * p_root_onelevel;
133 playlist_item_t * p_local_category; /** < "Playlist" in CATEGORY view */
134 playlist_item_t * p_ml_category; /** < "Library" in CATEGORY view */
135 playlist_item_t * p_local_onelevel; /** < "Playlist" in ONELEVEL view */
136 playlist_item_t * p_ml_onelevel; /** < "Library" in ONELEVEL iew */
138 vlc_bool_t b_always_tree;/**< Always display as tree */
139 vlc_bool_t b_never_tree;/**< Never display as tree */
142 input_thread_t * p_input; /**< the input thread associated
143 * with the current item */
144 int i_sort; /**< Last sorting applied to the playlist */
145 int i_order; /**< Last ordering applied to the playlist */
146 mtime_t i_vout_destroyed_date;
147 mtime_t i_sout_destroyed_date;
148 playlist_preparse_t *p_preparse; /**< Preparser object */
150 vlc_mutex_t gc_lock; /**< Lock to protect the garbage collection */
153 /* Current status. These fields are readonly, only the playlist
154 * main loop can touch it*/
155 playlist_status_t i_status; /**< Current status of playlist */
156 playlist_item_t * p_item; /**< Currently playing/active item */
157 playlist_item_t * p_node; /**< Current node to play from */
161 /* Request. Use this to give orders to the playlist main loop */
162 int i_status; /**< requested playlist status */
163 playlist_item_t * p_node; /**< requested node to play from */
164 playlist_item_t * p_item; /**< requested item to play in the node */
166 int i_skip; /**< Number of items to skip */
168 vlc_bool_t b_request;/**< Set to true by the requester
169 The playlist sets it back to false
170 when processing the request */
171 vlc_mutex_t lock; /**< Lock to protect request */
174 // Playlist-unrelated fields
175 interaction_t *p_interaction; /**< Interaction manager */
176 global_stats_t *p_stats; /**< Global statistics */
180 /* Helper to add an item */
181 struct playlist_add_t
190 #define SORT_TITLE_NODES_FIRST 2
191 #define SORT_ARTIST 3
193 #define SORT_RANDOM 5
194 #define SORT_DURATION 6
195 #define SORT_TITLE_NUMERIC 7
198 #define ORDER_NORMAL 0
199 #define ORDER_REVERSE 1
201 /*****************************************************************************
203 *****************************************************************************/
206 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
207 playlist_t *__playlist_ThreadCreate ( vlc_object_t * );
208 int playlist_ThreadDestroy ( playlist_t * );
211 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
212 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
214 /* Creation/Deletion */
215 playlist_t *playlist_Create ( vlc_object_t * );
216 void playlist_Destroy ( playlist_t * );
219 void playlist_MainLoop( playlist_t * );
220 void playlist_LastLoop( playlist_t * );
221 void playlist_PreparseLoop( playlist_preparse_t * );
224 playlist_item_t * playlist_NextItem ( playlist_t * );
225 int playlist_PlayItem ( playlist_t *, playlist_item_t * );
227 /* Playlist control */
228 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
229 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
230 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
231 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
232 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
233 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
235 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ... ) );
236 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ... ) );
238 VLC_EXPORT( void, playlist_Clear, ( playlist_t * ) );
239 VLC_EXPORT( void, playlist_LockClear, ( playlist_t * ) );
241 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
242 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
244 /* Services discovery */
246 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
247 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
248 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
249 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
251 /* Playlist sorting */
252 VLC_EXPORT( int, playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
253 VLC_EXPORT( int, playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
254 VLC_EXPORT( int, playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
257 VLC_EXPORT( int, playlist_Import, ( playlist_t *, const char *, playlist_item_t *, vlc_bool_t ) );
258 VLC_EXPORT( int, playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
260 /********************************************************
262 ********************************************************/
264 /*************************** Item creation **************************/
266 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char **, int, int) );
268 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
269 /** Create a new item, without adding it to the playlist
270 * \param p_obj a vlc object (anyone will do)
271 * \param psz_uri the mrl of the item
272 * \param psz_name a text giving a name or description of the item
273 * \return the new item or NULL on failure
275 static inline playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
276 const char *psz_uri, const char *psz_name )
278 /* 0 = ITEM_TYPE_UNKNOWN */
279 return playlist_ItemNewWithType( p_obj, psz_uri, psz_name, 0, NULL, -1,0);
282 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
283 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
285 /*************************** Item deletion **************************/
286 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
287 VLC_EXPORT( int, playlist_DeleteAllFromInput, ( playlist_t *, int ) );
288 VLC_EXPORT( int, playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
289 VLC_EXPORT( int, playlist_DeleteFromItemId, ( playlist_t *, int ) );
290 VLC_EXPORT( int, playlist_LockDelete, ( playlist_t *, int ) );
291 VLC_EXPORT( int, playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
293 /*************************** Item fields accessors **************************/
294 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, char * ) );
296 /******************** Item addition ********************/
297 VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
298 VLC_EXPORT( int, playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char **,int, vlc_bool_t ) );
299 VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
300 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
301 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
302 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
303 VLC_EXPORT( void, playlist_AddWhereverNeeded, (playlist_t* , input_item_t*, playlist_item_t*,playlist_item_t*,vlc_bool_t, int ) );
305 /** Add a MRL into the playlist.
308 static inline int playlist_PlaylistAdd( playlist_t *p_playlist,
309 const char *psz_uri, const char *psz_name,
310 int i_mode, int i_pos )
312 return playlist_Add( p_playlist, psz_uri, psz_name, i_mode, i_pos,
316 /** Add a MRL to the media library
319 static inline int playlist_MLAdd( playlist_t *p_playlist, const char *psz_uri,
320 const char *psz_name, int i_mode, int i_pos )
322 return playlist_Add( p_playlist, psz_uri, psz_name, i_mode, i_pos,
326 /** Add a MRL to the playlist, with duration and options given
327 * \see playlist_AddExt
329 static inline int playlist_PlaylistAddExt( playlist_t *p_playlist,
330 const char * psz_uri, const char *psz_name, int i_mode, int i_pos,
331 mtime_t i_duration, const char **ppsz_options, int i_options )
333 return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
334 i_duration, ppsz_options, i_options, VLC_TRUE );
337 /** Add a MRL to the media library, with duration and options given
338 * \see playlist_AddExt
340 static inline int playlist_MLAddExt( playlist_t *p_playlist,
341 const char * psz_uri, const char *psz_name, int i_mode, int i_pos,
342 mtime_t i_duration, const char **ppsz_options, int i_options )
344 return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
345 i_duration, ppsz_options, i_options, VLC_FALSE );
348 /** Add an input item to the playlist node
349 * \see playlist_AddInput
351 static inline int playlist_PlaylistAddInput( playlist_t* p_playlist,
352 input_item_t *p_input, int i_mode, int i_pos )
354 return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, VLC_TRUE );
357 /** Add an input item to the media library
358 * \see playlist_AddInput
360 static inline int playlist_MLAddInput( playlist_t* p_playlist,
361 input_item_t *p_input, int i_mode, int i_pos )
363 return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, VLC_FALSE );
366 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id, int i_node_id );
368 /********************** Misc item operations **********************/
369 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
370 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
372 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
373 int i_input_id, playlist_item_t *p_root );
375 /********************************** Item search *************************/
376 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
377 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
379 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
382 playlist_item_t *p_ret;
383 vlc_mutex_lock( &p_playlist->object_lock );
384 p_ret = playlist_ItemGetById( p_playlist, i_id );
385 vlc_mutex_unlock( &p_playlist->object_lock );
389 static inline playlist_item_t *playlist_LockItemGetByInput(
390 playlist_t *p_playlist, input_item_t *p_item )
392 playlist_item_t *p_ret;
393 vlc_mutex_lock( &p_playlist->object_lock );
394 p_ret = playlist_ItemGetByInput( p_playlist, p_item );
395 vlc_mutex_unlock( &p_playlist->object_lock );
399 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
401 /********************************************************
403 ********************************************************/
404 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
405 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
407 /* Node management */
408 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, char *, playlist_item_t * p_parent ) );
409 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
410 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
411 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
412 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
413 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
414 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
415 VLC_EXPORT( void, playlist_NodesCreateForSD, (playlist_t *, char *, playlist_item_t **, playlist_item_t ** ) );
416 VLC_EXPORT( playlist_item_t *, playlist_GetPreferredNode, ( playlist_t *p_playlist, playlist_item_t *p_node ) );
418 /* Tree walking - These functions are only for playlist, not plugins */
419 playlist_item_t *playlist_GetNextLeaf( playlist_t *p_playlist,
420 playlist_item_t *p_root,
421 playlist_item_t *, vlc_bool_t, vlc_bool_t );
422 playlist_item_t *playlist_GetPrevLeaf( playlist_t *p_playlist,
423 playlist_item_t *p_root,
424 playlist_item_t *, vlc_bool_t, vlc_bool_t );
425 playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist,
426 playlist_item_t *p_root );
428 /***********************************************************************
430 ***********************************************************************/
432 /** Tell if the playlist is currently running */
433 static inline vlc_bool_t playlist_IsPlaying( playlist_t * p_playlist )
435 vlc_bool_t b_playing;
436 vlc_mutex_lock( &p_playlist->object_lock );
437 b_playing = p_playlist->status.i_status == PLAYLIST_RUNNING;
438 vlc_mutex_unlock( &p_playlist->object_lock );
442 /** Tell if the playlist is empty */
443 static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist )
446 vlc_mutex_lock( &p_playlist->object_lock );
447 b_empty = p_playlist->i_size == 0;
448 vlc_mutex_unlock( &p_playlist->object_lock );
456 #define PLAYLIST_DEBUG 1
458 #ifdef PLAYLIST_DEBUG
459 #define PL_DEBUG( msg, args... ) msg_Dbg( p_playlist, msg, ## args )
461 #define PL_DEBUG( msg, args ... ) {}
464 #define PLI_NAME( p ) p ? p->p_input->psz_name : "null"