]> git.sesse.net Git - vlc/blob - include/vlc_playlist.h
Start grabbing hotkeys in Qt. Unfinished
[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 struct playlist_preparse_t
93 {
94     VLC_COMMON_MEMBERS
95     vlc_mutex_t     lock;
96     int             i_waiting;
97     input_item_t  **pp_waiting;
98 };
99
100
101 /** Structure containing information about the playlist */
102 struct playlist_t
103 {
104     VLC_COMMON_MEMBERS
105 /**
106    \name playlist_t
107    These members are uniq to playlist_t
108 */
109 /*@{*/
110     int                   i_enabled; /**< How many items are enabled ? */
111
112     /* Arrays of items */
113     int                   i_size;   /**< total size of the list */
114     playlist_item_t **    pp_items; /**< array of pointers to the
115                                      * playlist items */
116     int                   i_all_size; /**< size of list of items and nodes */
117     playlist_item_t **    pp_all_items; /**< array of pointers to the
118                                          * playlist items and nodes */
119     int                   i_input_items;
120     input_item_t **       pp_input_items;
121
122     int                   i_random;     /**< Number of candidates for random */
123     playlist_item_t **    pp_random;    /**< Random candidate items */
124     int                   i_random_index; /**< Current random item */
125     vlc_bool_t            b_reset_random; /**< Recreate random array ?*/
126
127     int                   i_last_playlist_id; /**< Last id to an item */
128     int                   i_last_input_id ; /**< Last id on an input */
129
130     services_discovery_t **pp_sds;
131     int                   i_sds;
132
133     /* Predefined items */
134     playlist_item_t *     p_root_category;
135     playlist_item_t *     p_root_onelevel;
136     playlist_item_t *     p_local_category; /** < "Playlist" in CATEGORY view */
137     playlist_item_t *     p_ml_category; /** < "Library" in CATEGORY view */
138     playlist_item_t *     p_local_onelevel; /** < "Playlist" in ONELEVEL view */
139     playlist_item_t *     p_ml_onelevel; /** < "Library" in ONELEVEL iew */
140
141     vlc_bool_t            b_always_tree;/**< Always display as tree */
142     vlc_bool_t            b_never_tree;/**< Never display as tree */
143
144     vlc_bool_t            b_doing_ml; /**< Doing media library stuff, */
145                                       /*get quicker */
146
147     /* Runtime */
148     input_thread_t *      p_input;  /**< the input thread associated
149                                      * with the current item */
150     int                   i_sort; /**< Last sorting applied to the playlist */
151     int                   i_order; /**< Last ordering applied to the playlist */
152     mtime_t               i_vout_destroyed_date;
153     mtime_t               i_sout_destroyed_date;
154     playlist_preparse_t  *p_preparse; /**< Preparser object */
155
156     vlc_mutex_t gc_lock;         /**< Lock to protect the garbage collection */
157
158     struct {
159         /* Current status. These fields are readonly, only the playlist
160          * main loop can touch it*/
161         playlist_status_t   i_status;  /**< Current status of playlist */
162         playlist_item_t *   p_item; /**< Currently playing/active item */
163         playlist_item_t *   p_node; /**< Current node to play from */
164     } status;
165
166     struct {
167         /* Request. Use this to give orders to the playlist main loop  */
168         int                 i_status; /**< requested playlist status */
169         playlist_item_t *   p_node;   /**< requested node to play from */
170         playlist_item_t *   p_item;   /**< requested item to play in the node */
171
172         int                 i_skip;   /**< Number of items to skip */
173
174         vlc_bool_t          b_request;/**< Set to true by the requester
175                                            The playlist sets it back to false
176                                            when processing the request */
177         vlc_mutex_t         lock;     /**< Lock to protect request */
178     } request;
179
180     // Playlist-unrelated fields
181     interaction_t       *p_interaction;       /**< Interaction manager */
182     global_stats_t      *p_stats;             /**< Global statistics */
183     /*@}*/
184 };
185
186 /* Helper to add an item */
187 struct playlist_add_t
188 {
189     int i_node;
190     int i_item;
191     int i_position;
192 };
193
194 #define SORT_ID 0
195 #define SORT_TITLE 1
196 #define SORT_TITLE_NODES_FIRST 2
197 #define SORT_ARTIST 3
198 #define SORT_GENRE 4
199 #define SORT_RANDOM 5
200 #define SORT_DURATION 6
201 #define SORT_TITLE_NUMERIC 7
202 #define SORT_ALBUM 8
203
204 #define ORDER_NORMAL 0
205 #define ORDER_REVERSE 1
206
207 /*****************************************************************************
208  * Prototypes
209  *****************************************************************************/
210
211 /* Global thread */
212 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
213 playlist_t *__playlist_ThreadCreate   ( vlc_object_t * );
214 int           playlist_ThreadDestroy  ( playlist_t * );
215
216 /* Helpers */
217 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
218 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
219
220 /* Creation/Deletion */
221 playlist_t *playlist_Create   ( vlc_object_t * );
222 void        playlist_Destroy  ( playlist_t * );
223
224 /* Engine */
225 void playlist_MainLoop( playlist_t * );
226 void playlist_LastLoop( playlist_t * );
227 void playlist_PreparseLoop( playlist_preparse_t * );
228
229 /* Control */
230 playlist_item_t * playlist_NextItem  ( playlist_t * );
231 int playlist_PlayItem  ( playlist_t *, playlist_item_t * );
232
233 /* Playlist control */
234 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
235 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
236 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
237 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
238 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
239 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
240
241 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ...  ) );
242 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ...  ) );
243
244 VLC_EXPORT( void,  playlist_Clear, ( playlist_t * ) );
245 VLC_EXPORT( void,  playlist_LockClear, ( playlist_t * ) );
246
247 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
248 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
249
250 /* Services discovery */
251
252 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
253 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
254 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
255 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
256
257 /* Playlist sorting */
258 VLC_EXPORT( int,  playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
259 VLC_EXPORT( int,  playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
260 VLC_EXPORT( int,  playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
261
262 /* Load/Save */
263 VLC_EXPORT( int,  playlist_Import, ( playlist_t *, const char *, playlist_item_t *, vlc_bool_t ) );
264 VLC_EXPORT( int,  playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
265 int playlist_MLLoad( playlist_t *p_playlist );
266 int playlist_MLDump( playlist_t *p_playlist );
267
268 /********************************************************
269  * Item management
270  ********************************************************/
271
272 /*************************** Item creation **************************/
273
274 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char **, int, int) );
275
276 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
277 /** Create a new item, without adding it to the playlist
278  * \param p_obj a vlc object (anyone will do)
279  * \param psz_uri the mrl of the item
280  * \param psz_name a text giving a name or description of the item
281  * \return the new item or NULL on failure
282  */
283 static inline playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
284                                      const char *psz_uri, const char *psz_name )
285 {
286     /* 0 = ITEM_TYPE_UNKNOWN */
287     return playlist_ItemNewWithType( p_obj, psz_uri,  psz_name, 0, NULL, -1,0);
288 }
289
290 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
291 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
292
293 /*************************** Item deletion **************************/
294 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
295 VLC_EXPORT( int,  playlist_DeleteAllFromInput, ( playlist_t *, int ) );
296 VLC_EXPORT( int,  playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
297 VLC_EXPORT( int,  playlist_DeleteFromItemId, ( playlist_t *, int ) );
298 VLC_EXPORT( int,  playlist_LockDelete, ( playlist_t *, int ) );
299 VLC_EXPORT( int,  playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
300
301 /*************************** Item fields accessors **************************/
302 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *,  char * ) );
303
304 /******************** Item addition ********************/
305 VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
306 VLC_EXPORT( int,  playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char **,int, vlc_bool_t ) );
307 VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
308 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
309 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
310 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
311 VLC_EXPORT( void, playlist_AddWhereverNeeded, (playlist_t* , input_item_t*, playlist_item_t*,playlist_item_t*,vlc_bool_t, int ) );
312
313 /** Add a MRL into the playlist.
314  * \see playlist_Add
315  */
316 static inline int playlist_PlaylistAdd( playlist_t *p_playlist,
317                           const char *psz_uri, const char *psz_name,
318                           int i_mode, int i_pos )
319 {
320     return playlist_Add( p_playlist, psz_uri, psz_name, i_mode, i_pos,
321                          VLC_TRUE);
322 }
323
324 /** Add a MRL to the media library
325  * \see playlist_Add
326  */
327 static inline int playlist_MLAdd( playlist_t *p_playlist, const char *psz_uri,
328                                   const char *psz_name, int i_mode, int i_pos )
329 {
330     return playlist_Add( p_playlist, psz_uri, psz_name, i_mode, i_pos,
331                          VLC_FALSE );
332 }
333
334 /** Add a MRL to the playlist, with duration and options given
335  * \see playlist_AddExt
336  */
337 static inline int playlist_PlaylistAddExt( playlist_t *p_playlist,
338             const char * psz_uri, const char *psz_name, int i_mode, int i_pos,
339             mtime_t i_duration, const char **ppsz_options, int i_options ) 
340 {
341     return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
342                             i_duration, ppsz_options, i_options, VLC_TRUE );
343 }
344
345 /** Add a MRL to the media library, with duration and options given
346  * \see playlist_AddExt
347  */
348 static inline int playlist_MLAddExt( playlist_t *p_playlist,
349             const char * psz_uri, const char *psz_name, int i_mode, int i_pos,
350             mtime_t i_duration, const char **ppsz_options, int i_options ) 
351 {
352     return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
353                             i_duration, ppsz_options, i_options, VLC_FALSE );
354 }
355
356 /** Add an input item to the playlist node 
357  * \see playlist_AddInput
358  */
359 static inline int playlist_PlaylistAddInput( playlist_t* p_playlist,
360                                 input_item_t *p_input, int i_mode, int i_pos )
361 {
362     return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, VLC_TRUE );
363 }
364
365 /** Add an input item to the media library 
366  * \see playlist_AddInput
367  */
368 static inline int playlist_MLAddInput( playlist_t* p_playlist,
369                                 input_item_t *p_input, int i_mode, int i_pos )
370 {
371     return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, VLC_FALSE );
372 }
373
374 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id, int i_node_id );
375
376 /********************** Misc item operations **********************/
377 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
378 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
379
380 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
381                                    int i_input_id, playlist_item_t *p_root );
382
383 /********************************** Item search *************************/
384 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
385 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
386
387 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
388                                                          int i_id)
389 {
390     playlist_item_t *p_ret;
391     vlc_mutex_lock( &p_playlist->object_lock );
392     p_ret = playlist_ItemGetById( p_playlist, i_id );
393     vlc_mutex_unlock( &p_playlist->object_lock );
394     return p_ret;
395 }
396
397 static inline playlist_item_t *playlist_LockItemGetByInput(
398                                 playlist_t *p_playlist, input_item_t *p_item )
399 {
400     playlist_item_t *p_ret;
401     vlc_mutex_lock( &p_playlist->object_lock );
402     p_ret = playlist_ItemGetByInput( p_playlist, p_item );
403     vlc_mutex_unlock( &p_playlist->object_lock );
404     return p_ret;
405 }
406
407 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
408
409 /********************************************************
410  * Tree management
411  ********************************************************/
412 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
413 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
414
415 /* Node management */
416 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, char *, playlist_item_t * p_parent ) );
417 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
418 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
419 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
420 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
421 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
422 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
423 VLC_EXPORT( void, playlist_NodesCreateForSD, (playlist_t *, char *, playlist_item_t **, playlist_item_t ** ) );
424 VLC_EXPORT( playlist_item_t *, playlist_GetPreferredNode, ( playlist_t *p_playlist, playlist_item_t *p_node ) );
425
426 /* Tree walking - These functions are only for playlist, not plugins */
427 int playlist_GetAllEnabledChildren( playlist_t *p_playlist,
428                                     playlist_item_t *p_node,
429                                     playlist_item_t ***ppp_items );
430 playlist_item_t *playlist_GetNextLeaf( playlist_t *p_playlist,
431                                     playlist_item_t *p_root,
432                                     playlist_item_t *, vlc_bool_t, vlc_bool_t );
433 playlist_item_t *playlist_GetPrevLeaf( playlist_t *p_playlist,
434                                     playlist_item_t *p_root,
435                                     playlist_item_t *, vlc_bool_t, vlc_bool_t );
436 playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist,
437                                     playlist_item_t *p_root );
438
439 /***********************************************************************
440  * Inline functions
441  ***********************************************************************/
442
443 /** Tell if the playlist is currently running */
444 static inline vlc_bool_t playlist_IsPlaying( playlist_t * p_playlist )
445 {
446     vlc_bool_t b_playing;
447     vlc_mutex_lock( &p_playlist->object_lock );
448     b_playing = p_playlist->status.i_status == PLAYLIST_RUNNING;
449     vlc_mutex_unlock( &p_playlist->object_lock );
450     return( b_playing );
451 }
452
453 /** Tell if the playlist is empty */
454 static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist )
455 {
456     vlc_bool_t b_empty;
457     vlc_mutex_lock( &p_playlist->object_lock );
458     b_empty = p_playlist->i_size == 0;
459     vlc_mutex_unlock( &p_playlist->object_lock );
460     return( b_empty );
461 }
462
463 /**
464  * @}
465  */
466
467 #define PLAYLIST_DEBUG 1
468
469 #ifdef PLAYLIST_DEBUG
470 #define PL_DEBUG( msg, args... ) msg_Dbg( p_playlist, msg, ## args )
471 #else
472 #define PL_DEBUG( msg, args ... ) {}
473 #endif
474
475 #define PLI_NAME( p ) p ? p->p_input->psz_name : "null"
476
477 #endif