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_
28 #include <vlc_input.h>
32 TYPEDEF_ARRAY(playlist_item_t*, playlist_item_array_t);
33 TYPEDEF_ARRAY(input_item_t*, input_item_array_t);
36 * This file contain structures and function prototypes related
37 * to the playlist in vlc
39 * \defgroup vlc_playlist Playlist
44 * playlist export helper structure
46 struct playlist_export_t
50 playlist_item_t *p_root;
54 * playlist item / node
57 struct playlist_item_t
59 input_item_t *p_input; /**< input item descriptor */
61 /* Tree specific fields */
62 int i_children; /**< Number of children
64 playlist_item_t **pp_children; /**< Children nodes/items */
65 playlist_item_t *p_parent; /**< Item parent */
67 int i_id; /**< Playlist item specific id */
69 uint8_t i_flags; /**< Flags */
72 #define PLAYLIST_SAVE_FLAG 0x0001 /**< Must it be saved */
73 #define PLAYLIST_SKIP_FLAG 0x0002 /**< Must playlist skip after it ? */
74 #define PLAYLIST_DBL_FLAG 0x0004 /**< Is it disabled ? */
75 #define PLAYLIST_RO_FLAG 0x0008 /**< Write-enabled ? */
76 #define PLAYLIST_REMOVE_FLAG 0x0010 /**< Remove this item at the end */
77 #define PLAYLIST_EXPANDED_FLAG 0x0020 /**< Expanded node */
79 /** Playlist status */
81 { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
84 struct services_discovery_t
91 services_discovery_sys_t *p_sys;
92 void (*pf_run) ( services_discovery_t *);
95 /** Structure containing information about the playlist */
99 int i_enabled; /**< How many items are enabled ? */
101 playlist_item_array_t items; /**< Arrays of items */
102 playlist_item_array_t all_items; /**< Array of items and nodes */
104 input_item_array_t input_items; /**< Array of input items */
106 playlist_item_array_t current; /**< Items currently being played */
107 int i_current_index; /**< Index in current array */
108 /** Reset current item ? */
109 vlc_bool_t b_reset_currently_playing;
110 mtime_t last_rebuild_date;
112 int i_last_playlist_id; /**< Last id to an item */
113 int i_last_input_id ; /**< Last id on an input */
115 services_discovery_t **pp_sds;
118 /* Predefined items */
119 playlist_item_t * p_root_category;
120 playlist_item_t * p_root_onelevel;
121 playlist_item_t * p_local_category; /** < "Playlist" in CATEGORY view */
122 playlist_item_t * p_ml_category; /** < "Library" in CATEGORY view */
123 playlist_item_t * p_local_onelevel; /** < "Playlist" in ONELEVEL view */
124 playlist_item_t * p_ml_onelevel; /** < "Library" in ONELEVEL iew */
126 vlc_bool_t b_always_tree;/**< Always display as tree */
127 vlc_bool_t b_never_tree;/**< Never display as tree */
129 vlc_bool_t b_doing_ml; /**< Doing media library stuff, */
131 vlc_bool_t b_auto_preparse;
134 input_thread_t * p_input; /**< the input thread associated
135 * with the current item */
136 int i_sort; /**< Last sorting applied to the playlist */
137 int i_order; /**< Last ordering applied to the playlist */
139 vlc_bool_t b_cant_sleep;
140 playlist_preparse_t *p_preparse; /**< Preparser object */
141 playlist_fetcher_t *p_fetcher;/**< Meta and art fetcher object */
143 vlc_mutex_t gc_lock; /**< Lock to protect the garbage collection */
146 /* Current status. These fields are readonly, only the playlist
147 * main loop can touch it*/
148 playlist_status_t i_status; /**< Current status of playlist */
149 playlist_item_t * p_item; /**< Currently playing/active item */
150 playlist_item_t * p_node; /**< Current node to play from */
154 /* Request. Use this to give orders to the playlist main loop */
155 int i_status; /**< requested playlist status */
156 playlist_item_t * p_node; /**< requested node to play from */
157 playlist_item_t * p_item; /**< requested item to play in the node */
159 int i_skip; /**< Number of items to skip */
161 vlc_bool_t b_request;/**< Set to true by the requester
162 The playlist sets it back to false
163 when processing the request */
164 vlc_mutex_t lock; /**< Lock to protect request */
167 // Playlist-unrelated fields
168 interaction_t *p_interaction; /**< Interaction manager */
169 /** The input thread computing stats */
170 input_thread_t *p_stats_computer;
171 global_stats_t *p_stats; /**< Global statistics */
174 /** Helper to add an item */
175 struct playlist_add_t
184 #define SORT_TITLE_NODES_FIRST 2
185 #define SORT_ARTIST 3
187 #define SORT_RANDOM 5
188 #define SORT_DURATION 6
189 #define SORT_TITLE_NUMERIC 7
192 #define ORDER_NORMAL 0
193 #define ORDER_REVERSE 1
195 /*****************************************************************************
197 *****************************************************************************/
200 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
201 void __playlist_ThreadCreate ( vlc_object_t * );
202 int playlist_ThreadDestroy ( playlist_t * );
205 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
206 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
208 #define pl_Get( a ) a->p_libvlc->p_playlist
209 #define pl_Yield( a ) __pl_Yield( VLC_OBJECT(a) )
210 static inline playlist_t *__pl_Yield( vlc_object_t *p_this )
212 assert( p_this->p_libvlc->p_playlist );
213 vlc_object_yield( p_this->p_libvlc->p_playlist );
214 return p_this->p_libvlc->p_playlist;
216 #define pl_Release(a) vlc_object_release( a->p_libvlc->p_playlist );
218 /* Playlist control */
219 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
220 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
221 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
222 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
223 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
224 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
226 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ... ) );
227 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ... ) );
229 VLC_EXPORT( void, playlist_Clear, ( playlist_t * ) );
230 VLC_EXPORT( void, playlist_LockClear, ( playlist_t * ) );
232 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
233 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
234 VLC_EXPORT( int, playlist_AskForArtEnqueue, (playlist_t *, input_item_t *) );
236 /* Services discovery */
238 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
239 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
240 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
241 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
243 /* Playlist sorting */
244 VLC_EXPORT( int, playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
245 VLC_EXPORT( int, playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
246 VLC_EXPORT( int, playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
249 VLC_EXPORT( int, playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
251 /********************************************************
253 ********************************************************/
255 /*************************** Item creation **************************/
257 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char *const *, int, int) );
259 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
260 /** Create a new item, without adding it to the playlist
261 * \param p_obj a vlc object (anyone will do)
262 * \param psz_uri the mrl of the item
263 * \param psz_name a text giving a name or description of the item
264 * \return the new item or NULL on failure
266 static inline playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
267 const char *psz_uri, const char *psz_name )
269 /* 0 = ITEM_TYPE_UNKNOWN */
270 return playlist_ItemNewWithType( p_obj, psz_uri, psz_name, 0, NULL, -1,0);
273 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
274 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
276 /*************************** Item deletion **************************/
277 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
278 VLC_EXPORT( int, playlist_DeleteAllFromInput, ( playlist_t *, int ) );
279 VLC_EXPORT( int, playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
280 VLC_EXPORT( int, playlist_DeleteFromItemId, ( playlist_t *, int ) );
281 VLC_EXPORT( int, playlist_LockDelete, ( playlist_t *, int ) );
282 VLC_EXPORT( int, playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
284 /*************************** Item fields accessors **************************/
285 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, const char * ) );
287 /******************** Item addition ********************/
288 VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
289 VLC_EXPORT( int, playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t ) );
290 VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
291 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
292 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
293 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
295 /********************** Misc item operations **********************/
296 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
297 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
299 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
300 int i_input_id, playlist_item_t *p_root,
303 /********************************** Item search *************************/
304 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
305 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
307 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
310 playlist_item_t *p_ret;
311 vlc_mutex_lock( &p_playlist->object_lock );
312 p_ret = playlist_ItemGetById( p_playlist, i_id );
313 vlc_mutex_unlock( &p_playlist->object_lock );
317 static inline playlist_item_t *playlist_LockItemGetByInput(
318 playlist_t *p_playlist, input_item_t *p_item )
320 playlist_item_t *p_ret;
321 vlc_mutex_lock( &p_playlist->object_lock );
322 p_ret = playlist_ItemGetByInput( p_playlist, p_item );
323 vlc_mutex_unlock( &p_playlist->object_lock );
327 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
329 /********************************************************
331 ********************************************************/
332 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
333 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
335 /* Node management */
336 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, const char *, playlist_item_t * p_parent ) );
337 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
338 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
339 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
340 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
341 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
342 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
343 VLC_EXPORT( void, playlist_NodesPairCreate, (playlist_t *, const char *, playlist_item_t **, playlist_item_t **, vlc_bool_t ) );
344 VLC_EXPORT( playlist_item_t *, playlist_GetPreferredNode, ( playlist_t *p_playlist, playlist_item_t *p_node ) );
346 /***********************************************************************
348 ***********************************************************************/
349 /** Open a playlist file, add its content to the current playlist */
350 static inline int playlist_Import( playlist_t *p_playlist, const char *psz_file){
351 char psz_uri[256+10];
352 input_item_t *p_input;
353 snprintf( psz_uri, 256+9, "file/://%s", psz_file );
354 p_input = input_ItemNewExt( p_playlist, psz_uri, psz_file, 0, NULL, -1 );
355 playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END,
357 input_Read( p_playlist, p_input, VLC_TRUE );
361 /** Tell if the playlist is currently running */
362 #define playlist_IsPlaying( pl ) ( pl->status.i_status == PLAYLIST_RUNNING )
364 /** Tell if the playlist is empty */
365 #define playlist_IsEmpty( pl ) ( pl->items.i_size == 0 )
367 /** Tell the number of items in the current playing context */
368 #define playlist_CurrentSize( obj ) obj->p_libvlc->p_playlist->current.i_size
371 /** Ask the playlist to do some work */
372 static inline void playlist_Signal( playlist_t *p_playlist )
375 vlc_cond_signal( &p_playlist->object_wait );