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, */
133 input_thread_t * p_input; /**< the input thread associated
134 * with the current item */
135 int i_sort; /**< Last sorting applied to the playlist */
136 int i_order; /**< Last ordering applied to the playlist */
138 vlc_bool_t b_cant_sleep;
139 playlist_preparse_t *p_preparse; /**< Preparser object */
140 playlist_fetcher_t *p_fetcher;/**< Meta and art fetcher object */
142 vlc_mutex_t gc_lock; /**< Lock to protect the garbage collection */
145 /* Current status. These fields are readonly, only the playlist
146 * main loop can touch it*/
147 playlist_status_t i_status; /**< Current status of playlist */
148 playlist_item_t * p_item; /**< Currently playing/active item */
149 playlist_item_t * p_node; /**< Current node to play from */
153 /* Request. Use this to give orders to the playlist main loop */
154 int i_status; /**< requested playlist status */
155 playlist_item_t * p_node; /**< requested node to play from */
156 playlist_item_t * p_item; /**< requested item to play in the node */
158 int i_skip; /**< Number of items to skip */
160 vlc_bool_t b_request;/**< Set to true by the requester
161 The playlist sets it back to false
162 when processing the request */
163 vlc_mutex_t lock; /**< Lock to protect request */
166 // Playlist-unrelated fields
167 interaction_t *p_interaction; /**< Interaction manager */
168 /** The input thread computing stats */
169 input_thread_t *p_stats_computer;
170 global_stats_t *p_stats; /**< Global statistics */
173 /** Helper to add an item */
174 struct playlist_add_t
183 #define SORT_TITLE_NODES_FIRST 2
184 #define SORT_ARTIST 3
186 #define SORT_RANDOM 5
187 #define SORT_DURATION 6
188 #define SORT_TITLE_NUMERIC 7
191 #define ORDER_NORMAL 0
192 #define ORDER_REVERSE 1
194 /*****************************************************************************
196 *****************************************************************************/
199 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
200 void __playlist_ThreadCreate ( vlc_object_t * );
201 int playlist_ThreadDestroy ( playlist_t * );
204 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
205 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
207 #define pl_Get( a ) a->p_libvlc->p_playlist
208 #define pl_Yield( a ) __pl_Yield( VLC_OBJECT(a) )
209 static inline playlist_t *__pl_Yield( vlc_object_t *p_this )
211 assert( p_this->p_libvlc->p_playlist );
212 vlc_object_yield( p_this->p_libvlc->p_playlist );
213 return p_this->p_libvlc->p_playlist;
215 #define pl_Release(a) vlc_object_release( a->p_libvlc->p_playlist );
217 /* Playlist control */
218 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
219 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
220 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
221 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
222 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
223 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
225 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ... ) );
226 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ... ) );
228 VLC_EXPORT( void, playlist_Clear, ( playlist_t * ) );
229 VLC_EXPORT( void, playlist_LockClear, ( playlist_t * ) );
231 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
232 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
233 VLC_EXPORT( int, playlist_AskForArtEnqueue, (playlist_t *, input_item_t *) );
235 /* Services discovery */
237 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
238 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
239 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
240 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
242 /* Playlist sorting */
243 VLC_EXPORT( int, playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
244 VLC_EXPORT( int, playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
245 VLC_EXPORT( int, playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
248 VLC_EXPORT( int, playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
250 /********************************************************
252 ********************************************************/
254 /*************************** Item creation **************************/
256 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char *const *, int, int) );
258 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
259 /** Create a new item, without adding it to the playlist
260 * \param p_obj a vlc object (anyone will do)
261 * \param psz_uri the mrl of the item
262 * \param psz_name a text giving a name or description of the item
263 * \return the new item or NULL on failure
265 static inline playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
266 const char *psz_uri, const char *psz_name )
268 /* 0 = ITEM_TYPE_UNKNOWN */
269 return playlist_ItemNewWithType( p_obj, psz_uri, psz_name, 0, NULL, -1,0);
272 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
273 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
275 /*************************** Item deletion **************************/
276 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
277 VLC_EXPORT( int, playlist_DeleteAllFromInput, ( playlist_t *, int ) );
278 VLC_EXPORT( int, playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
279 VLC_EXPORT( int, playlist_DeleteFromItemId, ( playlist_t *, int ) );
280 VLC_EXPORT( int, playlist_LockDelete, ( playlist_t *, int ) );
281 VLC_EXPORT( int, playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
283 /*************************** Item fields accessors **************************/
284 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, const char * ) );
286 /******************** Item addition ********************/
287 VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
288 VLC_EXPORT( int, playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t ) );
289 VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
290 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
291 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
292 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
294 /********************** Misc item operations **********************/
295 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
296 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
298 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
299 int i_input_id, playlist_item_t *p_root,
302 /********************************** Item search *************************/
303 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
304 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
306 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
309 playlist_item_t *p_ret;
310 vlc_mutex_lock( &p_playlist->object_lock );
311 p_ret = playlist_ItemGetById( p_playlist, i_id );
312 vlc_mutex_unlock( &p_playlist->object_lock );
316 static inline playlist_item_t *playlist_LockItemGetByInput(
317 playlist_t *p_playlist, input_item_t *p_item )
319 playlist_item_t *p_ret;
320 vlc_mutex_lock( &p_playlist->object_lock );
321 p_ret = playlist_ItemGetByInput( p_playlist, p_item );
322 vlc_mutex_unlock( &p_playlist->object_lock );
326 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
328 /********************************************************
330 ********************************************************/
331 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
332 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
334 /* Node management */
335 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, const char *, playlist_item_t * p_parent ) );
336 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
337 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
338 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
339 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
340 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
341 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
342 VLC_EXPORT( void, playlist_NodesPairCreate, (playlist_t *, const char *, playlist_item_t **, playlist_item_t **, vlc_bool_t ) );
343 VLC_EXPORT( playlist_item_t *, playlist_GetPreferredNode, ( playlist_t *p_playlist, playlist_item_t *p_node ) );
345 /***********************************************************************
347 ***********************************************************************/
348 /** Open a playlist file, add its content to the current playlist */
349 static inline int playlist_Import( playlist_t *p_playlist, const char *psz_file){
350 char psz_uri[256+10];
351 input_item_t *p_input;
352 snprintf( psz_uri, 256+9, "file/://%s", psz_file );
353 p_input = input_ItemNewExt( p_playlist, psz_uri, psz_file, 0, NULL, -1 );
354 playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END,
356 input_Read( p_playlist, p_input, VLC_TRUE );
360 /** Tell if the playlist is currently running */
361 #define playlist_IsPlaying( pl ) ( pl->status.i_status == PLAYLIST_RUNNING )
363 /** Tell if the playlist is empty */
364 #define playlist_IsEmpty( pl ) ( pl->items.i_size == 0 )
366 /** Tell the number of items in the current playing context */
367 #define playlist_CurrentSize( obj ) obj->p_libvlc->p_playlist->current.i_size
370 /** Ask the playlist to do some work */
371 static inline void playlist_Signal( playlist_t *p_playlist )
374 vlc_cond_signal( &p_playlist->object_wait );