]> git.sesse.net Git - vlc/blob - include/vlc_playlist.h
Split playlist include file in public/private
[vlc] / include / vlc_playlist.h
1 /*****************************************************************************
2  * vlc_playlist.h : Playlist functions
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef _VLC_PLAYLIST_H_
25 #define _VLC_PLAYLIST_H_
26
27 /**
28  *  \file
29  *  This file contain structures and function prototypes related
30  *  to the playlist in vlc
31  */
32
33 /**
34  * \defgroup vlc_playlist Playlist
35  * @{
36  */
37
38 /**
39  * playlist export helper structure
40  */
41 struct playlist_export_t
42 {
43     char *psz_filename;
44     FILE *p_file;
45     playlist_item_t *p_root;
46 };
47
48 /**
49  * playlist item / node
50  * \see playlist_t
51  */
52 struct playlist_item_t
53 {
54     input_item_t           *p_input;    /**< input item descriptor */
55
56     /* Tree specific fields */
57     int                    i_children;  /**< Number of children
58                                              -1 if not a node */
59     playlist_item_t      **pp_children; /**< Children nodes/items */
60     playlist_item_t       *p_parent;    /**< Item parent */
61
62     int                    i_id;        /**< Playlist item specific id */
63
64     uint8_t                i_flags;     /**< Flags */
65 };
66
67 #define PLAYLIST_SAVE_FLAG      0x0001    /**< Must it be saved */
68 #define PLAYLIST_SKIP_FLAG      0x0002    /**< Must playlist skip after it ? */
69 #define PLAYLIST_DBL_FLAG       0x0004    /**< Is it disabled ? */
70 #define PLAYLIST_RO_FLAG        0x0008    /**< Write-enabled ? */
71 #define PLAYLIST_REMOVE_FLAG    0x0010    /**< Remove this item at the end */
72 #define PLAYLIST_EXPANDED_FLAG  0x0020    /**< Expanded node */
73
74 /**
75  * Playlist status
76  */
77 typedef enum
78 { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
79
80
81 struct services_discovery_t
82 {
83     VLC_COMMON_MEMBERS
84     char *psz_module;
85
86     module_t *p_module;
87
88     services_discovery_sys_t *p_sys;
89     void (*pf_run) ( services_discovery_t *);
90 };
91
92 /** Structure containing information about the playlist */
93 struct playlist_t
94 {
95     VLC_COMMON_MEMBERS
96 /**
97    \name playlist_t
98    These members are uniq to playlist_t
99 */
100 /*@{*/
101     int                   i_enabled; /**< How many items are enabled ? */
102
103     /* Arrays of items */
104     int                   i_size;   /**< total size of the list */
105     playlist_item_t **    pp_items; /**< array of pointers to the
106                                      * playlist items */
107     int                   i_all_size; /**< size of list of items and nodes */
108     playlist_item_t **    pp_all_items; /**< array of pointers to the
109                                          * playlist items and nodes */
110     int                   i_input_items;
111     input_item_t **       pp_input_items;
112
113     int                   i_random;     /**< Number of candidates for random */
114     playlist_item_t **    pp_random;    /**< Random candidate items */
115     int                   i_random_index; /**< Current random item */
116     vlc_bool_t            b_reset_random; /**< Recreate random array ?*/
117
118     int                   i_last_playlist_id; /**< Last id to an item */
119     int                   i_last_input_id ; /**< Last id on an input */
120
121     services_discovery_t **pp_sds;
122     int                   i_sds;
123
124     /* Predefined items */
125     playlist_item_t *     p_root_category;
126     playlist_item_t *     p_root_onelevel;
127     playlist_item_t *     p_local_category; /** < "Playlist" in CATEGORY view */
128     playlist_item_t *     p_ml_category; /** < "Library" in CATEGORY view */
129     playlist_item_t *     p_local_onelevel; /** < "Playlist" in ONELEVEL view */
130     playlist_item_t *     p_ml_onelevel; /** < "Library" in ONELEVEL iew */
131
132     vlc_bool_t            b_always_tree;/**< Always display as tree */
133     vlc_bool_t            b_never_tree;/**< Never display as tree */
134
135     vlc_bool_t            b_doing_ml; /**< Doing media library stuff, */
136                                       /*get quicker */
137
138     /* Runtime */
139     input_thread_t *      p_input;  /**< the input thread associated
140                                      * with the current item */
141     int                   i_sort; /**< Last sorting applied to the playlist */
142     int                   i_order; /**< Last ordering applied to the playlist */
143     mtime_t               i_vout_destroyed_date;
144     mtime_t               i_sout_destroyed_date;
145     playlist_preparse_t  *p_preparse; /**< Preparser object */
146
147     vlc_mutex_t gc_lock;         /**< Lock to protect the garbage collection */
148
149     struct {
150         /* Current status. These fields are readonly, only the playlist
151          * main loop can touch it*/
152         playlist_status_t   i_status;  /**< Current status of playlist */
153         playlist_item_t *   p_item; /**< Currently playing/active item */
154         playlist_item_t *   p_node; /**< Current node to play from */
155     } status;
156
157     struct {
158         /* Request. Use this to give orders to the playlist main loop  */
159         int                 i_status; /**< requested playlist status */
160         playlist_item_t *   p_node;   /**< requested node to play from */
161         playlist_item_t *   p_item;   /**< requested item to play in the node */
162
163         int                 i_skip;   /**< Number of items to skip */
164
165         vlc_bool_t          b_request;/**< Set to true by the requester
166                                            The playlist sets it back to false
167                                            when processing the request */
168         vlc_mutex_t         lock;     /**< Lock to protect request */
169     } request;
170
171     // Playlist-unrelated fields
172     interaction_t       *p_interaction;       /**< Interaction manager */
173     global_stats_t      *p_stats;             /**< Global statistics */
174     /*@}*/
175 };
176
177 /* Helper to add an item */
178 struct playlist_add_t
179 {
180     int i_node;
181     int i_item;
182     int i_position;
183 };
184
185 #define SORT_ID 0
186 #define SORT_TITLE 1
187 #define SORT_TITLE_NODES_FIRST 2
188 #define SORT_ARTIST 3
189 #define SORT_GENRE 4
190 #define SORT_RANDOM 5
191 #define SORT_DURATION 6
192 #define SORT_TITLE_NUMERIC 7
193 #define SORT_ALBUM 8
194
195 #define ORDER_NORMAL 0
196 #define ORDER_REVERSE 1
197
198 /*****************************************************************************
199  * Prototypes
200  *****************************************************************************/
201
202 /* Global thread */
203 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
204 playlist_t *__playlist_ThreadCreate   ( vlc_object_t * );
205 int           playlist_ThreadDestroy  ( playlist_t * );
206
207 /* Helpers */
208 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
209 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
210
211 /* Playlist control */
212 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
213 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
214 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
215 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
216 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
217 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
218
219 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ...  ) );
220 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ...  ) );
221
222 VLC_EXPORT( void,  playlist_Clear, ( playlist_t * ) );
223 VLC_EXPORT( void,  playlist_LockClear, ( playlist_t * ) );
224
225 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
226 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
227
228 /* Services discovery */
229
230 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
231 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
232 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
233 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
234
235 /* Playlist sorting */
236 VLC_EXPORT( int,  playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
237 VLC_EXPORT( int,  playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
238 VLC_EXPORT( int,  playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
239
240 /* Load/Save */
241 VLC_EXPORT( int,  playlist_Import, ( playlist_t *, const char *, playlist_item_t *, vlc_bool_t ) );
242 VLC_EXPORT( int,  playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
243
244 /********************************************************
245  * Item management
246  ********************************************************/
247
248 /*************************** Item creation **************************/
249
250 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char **, int, int) );
251
252 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
253 /** Create a new item, without adding it to the playlist
254  * \param p_obj a vlc object (anyone will do)
255  * \param psz_uri the mrl of the item
256  * \param psz_name a text giving a name or description of the item
257  * \return the new item or NULL on failure
258  */
259 static inline playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
260                                      const char *psz_uri, const char *psz_name )
261 {
262     /* 0 = ITEM_TYPE_UNKNOWN */
263     return playlist_ItemNewWithType( p_obj, psz_uri,  psz_name, 0, NULL, -1,0);
264 }
265
266 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
267 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
268
269 /*************************** Item deletion **************************/
270 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
271 VLC_EXPORT( int,  playlist_DeleteAllFromInput, ( playlist_t *, int ) );
272 VLC_EXPORT( int,  playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
273 VLC_EXPORT( int,  playlist_DeleteFromItemId, ( playlist_t *, int ) );
274 VLC_EXPORT( int,  playlist_LockDelete, ( playlist_t *, int ) );
275 VLC_EXPORT( int,  playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
276
277 /*************************** Item fields accessors **************************/
278 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *,  char * ) );
279
280 /******************** Item addition ********************/
281 VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
282 VLC_EXPORT( int,  playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char **,int, vlc_bool_t ) );
283 VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
284 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
285 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
286 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
287 VLC_EXPORT( void, playlist_AddWhereverNeeded, (playlist_t* , input_item_t*, playlist_item_t*,playlist_item_t*,vlc_bool_t, int ) );
288
289 /** Add a MRL into the playlist.
290  * \see playlist_Add
291  */
292 static inline int playlist_PlaylistAdd( playlist_t *p_playlist,
293                           const char *psz_uri, const char *psz_name,
294                           int i_mode, int i_pos )
295 {
296     return playlist_Add( p_playlist, psz_uri, psz_name, i_mode, i_pos,
297                          VLC_TRUE);
298 }
299
300 /** Add a MRL to the media library
301  * \see playlist_Add
302  */
303 static inline int playlist_MLAdd( playlist_t *p_playlist, const char *psz_uri,
304                                   const char *psz_name, int i_mode, int i_pos )
305 {
306     return playlist_Add( p_playlist, psz_uri, psz_name, i_mode, i_pos,
307                          VLC_FALSE );
308 }
309
310 /** Add a MRL to the playlist, with duration and options given
311  * \see playlist_AddExt
312  */
313 static inline int playlist_PlaylistAddExt( playlist_t *p_playlist,
314             const char * psz_uri, const char *psz_name, int i_mode, int i_pos,
315             mtime_t i_duration, const char **ppsz_options, int i_options ) 
316 {
317     return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
318                             i_duration, ppsz_options, i_options, VLC_TRUE );
319 }
320
321 /** Add a MRL to the media library, with duration and options given
322  * \see playlist_AddExt
323  */
324 static inline int playlist_MLAddExt( playlist_t *p_playlist,
325             const char * psz_uri, const char *psz_name, int i_mode, int i_pos,
326             mtime_t i_duration, const char **ppsz_options, int i_options ) 
327 {
328     return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
329                             i_duration, ppsz_options, i_options, VLC_FALSE );
330 }
331
332 /** Add an input item to the playlist node 
333  * \see playlist_AddInput
334  */
335 static inline int playlist_PlaylistAddInput( playlist_t* p_playlist,
336                                 input_item_t *p_input, int i_mode, int i_pos )
337 {
338     return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, VLC_TRUE );
339 }
340
341 /** Add an input item to the media library
342  * \see playlist_AddInput
343  */
344 static inline int playlist_MLAddInput( playlist_t* p_playlist,
345                                 input_item_t *p_input, int i_mode, int i_pos )
346 {
347     return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, VLC_FALSE );
348 }
349
350 /********************** Misc item operations **********************/
351 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
352 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
353
354 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
355                                    int i_input_id, playlist_item_t *p_root );
356
357 /********************************** Item search *************************/
358 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
359 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
360
361 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
362                                                          int i_id)
363 {
364     playlist_item_t *p_ret;
365     vlc_mutex_lock( &p_playlist->object_lock );
366     p_ret = playlist_ItemGetById( p_playlist, i_id );
367     vlc_mutex_unlock( &p_playlist->object_lock );
368     return p_ret;
369 }
370
371 static inline playlist_item_t *playlist_LockItemGetByInput(
372                                 playlist_t *p_playlist, input_item_t *p_item )
373 {
374     playlist_item_t *p_ret;
375     vlc_mutex_lock( &p_playlist->object_lock );
376     p_ret = playlist_ItemGetByInput( p_playlist, p_item );
377     vlc_mutex_unlock( &p_playlist->object_lock );
378     return p_ret;
379 }
380
381 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
382
383 /********************************************************
384  * Tree management
385  ********************************************************/
386 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
387 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
388
389 /* Node management */
390 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, char *, playlist_item_t * p_parent ) );
391 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
392 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
393 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
394 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
395 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
396 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
397 VLC_EXPORT( void, playlist_NodesCreateForSD, (playlist_t *, char *, playlist_item_t **, playlist_item_t ** ) );
398 VLC_EXPORT( playlist_item_t *, playlist_GetPreferredNode, ( playlist_t *p_playlist, playlist_item_t *p_node ) );
399
400 /***********************************************************************
401  * Inline functions
402  ***********************************************************************/
403
404 /** Tell if the playlist is currently running */
405 static inline vlc_bool_t playlist_IsPlaying( playlist_t * p_playlist )
406 {
407     vlc_bool_t b_playing;
408     vlc_mutex_lock( &p_playlist->object_lock );
409     b_playing = p_playlist->status.i_status == PLAYLIST_RUNNING;
410     vlc_mutex_unlock( &p_playlist->object_lock );
411     return( b_playing );
412 }
413
414 /** Tell if the playlist is empty */
415 static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist )
416 {
417     vlc_bool_t b_empty;
418     vlc_mutex_lock( &p_playlist->object_lock );
419     b_empty = p_playlist->i_size == 0;
420     vlc_mutex_unlock( &p_playlist->object_lock );
421     return( b_empty );
422 }
423
424 /**
425  * @}
426  */
427
428 #endif