]> git.sesse.net Git - vlc/blob - include/vlc_playlist.h
New helper to create nodes for services discovery
[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  * Brief description. Longer description
36  * @{
37  */
38
39 /**
40  * playlist export helper structure
41  */
42 struct playlist_export_t
43 {
44     char *psz_filename;
45     FILE *p_file;
46     playlist_item_t *p_root;
47 };
48
49 /**
50  * playlist item / node
51  * \see playlist_t
52  */
53 struct playlist_item_t
54 {
55     input_item_t           *p_input;    /**< input item descriptor */
56
57     /* Tree specific fields */
58     int                    i_children;  /**< Number of children
59                                              -1 if not a node */
60     playlist_item_t      **pp_children; /**< Children nodes/items */
61     playlist_item_t       *p_parent;    /**< Item parent */
62
63     int                    i_id;        /**< Playlist item specific id */
64
65     uint8_t                i_flags;     /**< Flags */
66 };
67
68 #define PLAYLIST_SAVE_FLAG      0x01    /**< Must it be saved */
69 #define PLAYLIST_SKIP_FLAG      0x02    /**< Must playlist skip after it ? */
70 #define PLAYLIST_DBL_FLAG       0x04    /**< Is it disabled ? */
71 #define PLAYLIST_RO_FLAG        0x10    /**< Write-enabled ? */
72 #define PLAYLIST_REMOVE_FLAG    0x20    /**< Remove this item at the end */
73 #define PLAYLIST_EXPANDED_FLAG  0x40    /**< Expanded node */
74
75 /**
76  * Playlist status
77  */
78 typedef enum
79 { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
80
81
82 struct services_discovery_t
83 {
84     VLC_COMMON_MEMBERS
85     char *psz_module;
86
87     module_t *p_module;
88
89     services_discovery_sys_t *p_sys;
90     void (*pf_run) ( services_discovery_t *);
91 };
92
93 struct playlist_preparse_t
94 {
95     VLC_COMMON_MEMBERS
96     vlc_mutex_t     lock;
97     int             i_waiting;
98     input_item_t  **pp_waiting;
99 };
100
101
102 /**
103  * Structure containing information about the playlist
104  */
105 struct playlist_t
106 {
107     VLC_COMMON_MEMBERS
108 /**
109    \name playlist_t
110    These members are uniq to playlist_t
111 */
112 /*@{*/
113     int                   i_enabled; /**< How many items are enabled ? */
114
115     int                   i_size;   /**< total size of the list */
116     playlist_item_t **    pp_items; /**< array of pointers to the
117                                      * playlist items */
118     int                   i_all_size; /**< size of list of items and nodes */
119     playlist_item_t **    pp_all_items; /**< array of pointers to the
120                                          * playlist items and nodes */
121     int                   i_last_playlist_id; /**< Last id to an item */
122
123     int                   i_input_items;
124     input_item_t **    pp_input_items;
125
126     int                  i_last_input_id ;
127
128     input_thread_t *      p_input;  /**< the input thread associated
129                                      * with the current item */
130
131     int                   i_sort; /**< Last sorting applied to the playlist */
132     int                   i_order; /**< Last ordering applied to the playlist */
133
134     playlist_item_t *     p_root_category;
135     playlist_item_t *     p_root_onelevel;
136
137     playlist_item_t *     p_local_category; /** < "Playlist" in CATEGORY view */
138     playlist_item_t *     p_ml_category; /** < "Library" in CATEGORY view */
139     playlist_item_t *     p_local_onelevel; /** < "Playlist" in ONELEVEL view */
140     playlist_item_t *     p_ml_onelevel; /** < "Library" in ONELEVEL iew */
141
142     services_discovery_t **pp_sds;
143     int                   i_sds;
144
145     struct {
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 */
151     } status;
152
153     struct {
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 */
158
159         int                 i_skip;   /**< Number of items to skip */
160
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 */
165     } request;
166
167     playlist_preparse_t     *p_preparse; /**< Preparser object */
168
169     vlc_mutex_t gc_lock;         /**< Lock to protect the garbage collection */
170
171     // Playlist-unrelated fields
172     interaction_t *p_interaction;       /**< Interaction manager */
173     global_stats_t *p_stats;            /**< Global statistics */
174
175     /*@}*/
176 };
177
178 /* Helper to add an item */
179 struct playlist_add_t
180 {
181     int i_node;
182     int i_item;
183     int i_view;
184     int i_position;
185 };
186
187 #define SORT_ID 0
188 #define SORT_TITLE 1
189 #define SORT_TITLE_NODES_FIRST 2
190 #define SORT_AUTHOR 3
191 #define SORT_GENRE 4
192 #define SORT_RANDOM 5
193 #define SORT_DURATION 6
194 #define SORT_TITLE_NUMERIC 7
195 #define SORT_ALBUM 8
196
197 #define ORDER_NORMAL 0
198 #define ORDER_REVERSE 1
199
200 /*****************************************************************************
201  * Prototypes
202  *****************************************************************************/
203
204 /* Global thread */
205 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
206 playlist_t *__playlist_ThreadCreate   ( vlc_object_t * );
207 int           playlist_ThreadDestroy  ( playlist_t * );
208
209 /* Helpers */
210 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
211 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
212
213 /* Creation/Deletion */
214 playlist_t *playlist_Create   ( vlc_object_t * );
215 void        playlist_Destroy  ( playlist_t * );
216
217 /* Engine */
218 void playlist_MainLoop( playlist_t * );
219 void playlist_LastLoop( playlist_t * );
220 void playlist_PreparseLoop( playlist_preparse_t * );
221
222 /* Control */
223 playlist_item_t * playlist_NextItem  ( playlist_t * );
224 int playlist_PlayItem  ( playlist_t *, playlist_item_t * );
225
226 /* Playlist control */
227 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
228 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
229 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
230 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
231 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
232 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
233
234 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ...  ) );
235 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ...  ) );
236
237 VLC_EXPORT( void,  playlist_Clear, ( playlist_t * ) );
238 VLC_EXPORT( void,  playlist_LockClear, ( playlist_t * ) );
239
240 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
241 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
242
243 /* Services discovery */
244
245 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
246 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
247 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
248 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
249
250
251 /* Item management functions (act on items) */
252 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
253 #define playlist_ItemCopy( a, b ) __playlist_ItemCopy(VLC_OBJECT(a), b )
254 VLC_EXPORT( playlist_item_t* , __playlist_ItemNew, ( vlc_object_t *,const char *,const char * ) );
255 VLC_EXPORT( playlist_item_t* , __playlist_ItemCopy, ( vlc_object_t *,playlist_item_t* ) );
256 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char **, int, int) );
257 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
258 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
259
260
261 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
262
263 /* Item informations accessors */
264 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *,  char * ) );
265 VLC_EXPORT( int, playlist_ItemSetDuration, (playlist_item_t *, mtime_t ) );
266
267 VLC_EXPORT( void, playlist_ItemAddOption, (playlist_item_t *, const char *) );
268
269 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
270
271 /** Counts the items of a view */
272 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
273
274 /* Node management */
275 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, char *, playlist_item_t * p_parent ) );
276 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
277 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
278 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
279 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
280 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
281 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
282 VLC_EXPORT( void, playlist_NodesCreateForSD, (playlist_t *, char *, playlist_item_t **, playlist_item_t ** ) );
283
284 /* Tree walking - These functions are only for playlist, not plugins */
285 playlist_item_t *playlist_GetNextLeaf( playlist_t *p_playlist,
286                                        playlist_item_t *p_root,
287                                        playlist_item_t *p_item );
288 playlist_item_t *playlist_GetNextEnabledLeaf( playlist_t *p_playlist,
289                                               playlist_item_t *p_root,
290                                               playlist_item_t *p_item );
291 playlist_item_t *playlist_GetPrevLeaf( playlist_t *p_playlist,
292                                        playlist_item_t *p_root,
293                                        playlist_item_t *p_item );
294 playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist,
295                                        playlist_item_t *p_root );
296
297
298 /* Simple add/remove functions */
299 VLC_EXPORT( int,  playlist_PlaylistAdd,    ( playlist_t *, const char *, const char *, int, int ) );
300 VLC_EXPORT( int,  playlist_PlaylistAddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char **,int ) );
301 VLC_EXPORT( int, playlist_PlaylistAddInput, ( playlist_t *, input_item_t *,int , int ) );
302 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
303 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
304 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
305 VLC_EXPORT( void, playlist_AddWhereverNeeded, (playlist_t* , input_item_t*, playlist_item_t*,playlist_item_t*,vlc_bool_t, int ) );
306
307 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id, int i_node_id );
308
309 /* Misc item operations (act on item+playlist) */
310 VLC_EXPORT( int,  playlist_DeleteAllFromInput, ( playlist_t *, int ) );
311 VLC_EXPORT( int,  playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
312 VLC_EXPORT( int,  playlist_DeleteFromItemId, ( playlist_t *, int ) );
313 VLC_EXPORT( int,  playlist_LockDelete, ( playlist_t *, int ) );
314 VLC_EXPORT( int,  playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
315 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
316 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
317
318 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
319                                    int i_input_id, playlist_item_t *p_root );
320
321 /* Item search functions */
322 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
323 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
324
325 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
326                                                          int i_id)
327 {
328     playlist_item_t *p_ret;
329     vlc_mutex_lock( &p_playlist->object_lock );
330     p_ret = playlist_ItemGetById( p_playlist, i_id );
331     vlc_mutex_unlock( &p_playlist->object_lock );
332     return p_ret;
333 }
334
335 static inline playlist_item_t *playlist_LockItemGetByInput(
336                                 playlist_t *p_playlist, input_item_t *p_item )
337 {
338     playlist_item_t *p_ret;
339     vlc_mutex_lock( &p_playlist->object_lock );
340     p_ret = playlist_ItemGetByInput( p_playlist, p_item );
341     vlc_mutex_unlock( &p_playlist->object_lock );
342     return p_ret;
343 }
344
345 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
346
347 /* Playlist sorting */
348 #define playlist_SortID(p, i) playlist_Sort( p, SORT_ID, i)
349 #define playlist_SortTitle(p, i) playlist_Sort( p, SORT_TITLE, i)
350 #define playlist_SortAuthor(p, i) playlist_Sort( p, SORT_AUTHOR, i)
351 #define playlist_SortAlbum(p, i) playlist_Sort( p, SORT_ALBUM, i)
352 #define playlist_SortGroup(p, i) playlist_Sort( p, SORT_GROUP, i)
353 VLC_EXPORT( int,  playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
354 VLC_EXPORT( int,  playlist_NodeGroup, ( playlist_t *, playlist_item_t *,playlist_item_t **,int, int, int ) );
355 VLC_EXPORT( int,  playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
356 VLC_EXPORT( int,  playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
357
358 /* Load/Save */
359 VLC_EXPORT( int,  playlist_Import, ( playlist_t *, const char * ) );
360 VLC_EXPORT( int,  playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
361
362 /***********************************************************************
363  * Inline functions
364  ***********************************************************************/
365
366 /** Tell if the playlist is currently running */
367 static inline vlc_bool_t playlist_IsPlaying( playlist_t * p_playlist )
368 {
369     vlc_bool_t b_playing;
370     vlc_mutex_lock( &p_playlist->object_lock );
371     b_playing = p_playlist->status.i_status == PLAYLIST_RUNNING;
372     vlc_mutex_unlock( &p_playlist->object_lock );
373     return( b_playing );
374 }
375
376 /** Tell if the playlist is empty */
377 static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist )
378 {
379     vlc_bool_t b_empty;
380     vlc_mutex_lock( &p_playlist->object_lock );
381     b_empty = p_playlist->i_size == 0;
382     vlc_mutex_unlock( &p_playlist->object_lock );
383     return( b_empty );
384 }
385
386 /**
387  * @}
388  */
389
390 #endif