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