]> git.sesse.net Git - vlc/blob - include/vlc_playlist.h
Preparse playlist items that don't have enough meta
[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 #include <vlc_input.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 TYPEDEF_ARRAY(playlist_item_t*, playlist_item_array_t);
33 TYPEDEF_ARRAY(input_item_t*, input_item_array_t);
34 /**
35  * \file
36  * This file contain structures and function prototypes related
37  * to the playlist in vlc
38  *
39  * \defgroup vlc_playlist Playlist
40  * @{
41  */
42
43 /**
44  * playlist export helper structure
45  */
46 struct playlist_export_t
47 {
48     char *psz_filename;
49     FILE *p_file;
50     playlist_item_t *p_root;
51 };
52
53 /**
54  * playlist item / node
55  * \see playlist_t
56  */
57 struct playlist_item_t
58 {
59     input_item_t           *p_input;    /**< input item descriptor */
60
61     /* Tree specific fields */
62     int                    i_children;  /**< Number of children
63                                              -1 if not a node */
64     playlist_item_t      **pp_children; /**< Children nodes/items */
65     playlist_item_t       *p_parent;    /**< Item parent */
66
67     int                    i_id;        /**< Playlist item specific id */
68
69     uint8_t                i_flags;     /**< Flags */
70 };
71
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 */
78
79 /** Playlist status */
80 typedef enum
81 { PLAYLIST_STOPPED,PLAYLIST_RUNNING,PLAYLIST_PAUSED } playlist_status_t;
82
83
84 struct services_discovery_t
85 {
86     VLC_COMMON_MEMBERS
87     char *psz_module;
88
89     module_t *p_module;
90
91     services_discovery_sys_t *p_sys;
92     void (*pf_run) ( services_discovery_t *);
93 };
94
95 /** Structure containing information about the playlist */
96 struct playlist_t
97 {
98     VLC_COMMON_MEMBERS
99     int                   i_enabled; /**< How many items are enabled ? */
100
101     playlist_item_array_t items; /**< Arrays of items */
102     playlist_item_array_t all_items; /**< Array of items and nodes */
103
104     input_item_array_t    input_items; /**< Array of input items */
105
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;
111
112     int                   i_last_playlist_id; /**< Last id to an item */
113     int                   i_last_input_id ; /**< Last id on an input */
114
115     services_discovery_t **pp_sds;
116     int                   i_sds;
117
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 */
125
126     vlc_bool_t            b_always_tree;/**< Always display as tree */
127     vlc_bool_t            b_never_tree;/**< Never display as tree */
128
129     vlc_bool_t            b_doing_ml; /**< Doing media library stuff, */
130                                       /*get quicker */
131     vlc_bool_t            b_auto_preparse;
132
133     /* Runtime */
134     input_thread_t *      p_input;  /**< the input thread associated
135                                      * with the current item */
136     int                   i_sort; /**< Last sorting applied to the playlist */
137     int                   i_order; /**< Last ordering applied to the playlist */
138     mtime_t               gc_date;
139     vlc_bool_t            b_cant_sleep;
140     playlist_preparse_t  *p_preparse; /**< Preparser object */
141     playlist_fetcher_t   *p_fetcher;/**< Meta and art fetcher object */
142
143     vlc_mutex_t gc_lock;         /**< Lock to protect the garbage collection */
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-unrelated fields
168     interaction_t       *p_interaction;       /**< Interaction manager */
169     /** The input thread computing stats */
170     input_thread_t      *p_stats_computer;
171     global_stats_t      *p_stats;             /**< Global statistics */
172 };
173
174 /** Helper to add an item */
175 struct playlist_add_t
176 {
177     int i_node;
178     int i_item;
179     int i_position;
180 };
181
182 #define SORT_ID 0
183 #define SORT_TITLE 1
184 #define SORT_TITLE_NODES_FIRST 2
185 #define SORT_ARTIST 3
186 #define SORT_GENRE 4
187 #define SORT_RANDOM 5
188 #define SORT_DURATION 6
189 #define SORT_TITLE_NUMERIC 7
190 #define SORT_ALBUM 8
191
192 #define ORDER_NORMAL 0
193 #define ORDER_REVERSE 1
194
195 /*****************************************************************************
196  * Prototypes
197  *****************************************************************************/
198
199 /* Global thread */
200 #define playlist_ThreadCreate(a) __playlist_ThreadCreate(VLC_OBJECT(a))
201 void        __playlist_ThreadCreate   ( vlc_object_t * );
202 int           playlist_ThreadDestroy  ( playlist_t * );
203
204 /* Helpers */
205 #define PL_LOCK vlc_mutex_lock( &p_playlist->object_lock );
206 #define PL_UNLOCK vlc_mutex_unlock( &p_playlist->object_lock );
207
208 #define pl_Get( a ) a->p_libvlc->p_playlist
209 #define pl_Yield( a ) __pl_Yield( VLC_OBJECT(a) )
210 static inline playlist_t *__pl_Yield( vlc_object_t *p_this )
211 {
212     assert( p_this->p_libvlc->p_playlist );
213     vlc_object_yield( p_this->p_libvlc->p_playlist );
214     return p_this->p_libvlc->p_playlist;
215 }
216 #define pl_Release(a) vlc_object_release( a->p_libvlc->p_playlist );
217
218 /* Playlist control */
219 #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
220 #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
221 #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
222 #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
223 #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
224 #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
225
226 VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ...  ) );
227 VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ...  ) );
228
229 VLC_EXPORT( void,  playlist_Clear, ( playlist_t * ) );
230 VLC_EXPORT( void,  playlist_LockClear, ( playlist_t * ) );
231
232 VLC_EXPORT( int, playlist_PreparseEnqueue, (playlist_t *, input_item_t *) );
233 VLC_EXPORT( int, playlist_PreparseEnqueueItem, (playlist_t *, playlist_item_t *) );
234 VLC_EXPORT( int, playlist_AskForArtEnqueue, (playlist_t *, input_item_t *) );
235
236 /* Services discovery */
237
238 VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
239 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
240 VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
241 VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
242
243 /* Playlist sorting */
244 VLC_EXPORT( int,  playlist_TreeMove, ( playlist_t *, playlist_item_t *, playlist_item_t *, int ) );
245 VLC_EXPORT( int,  playlist_NodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
246 VLC_EXPORT( int,  playlist_RecursiveNodeSort, ( playlist_t *, playlist_item_t *,int, int ) );
247
248 /* Load/Save */
249 VLC_EXPORT( int,  playlist_Export, ( playlist_t *, const char *, playlist_item_t *, const char * ) );
250
251 /********************************************************
252  * Item management
253  ********************************************************/
254
255 /*************************** Item creation **************************/
256
257 VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int , const char *const *, int, int) );
258
259 #define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
260 /** Create a new item, without adding it to the playlist
261  * \param p_obj a vlc object (anyone will do)
262  * \param psz_uri the mrl of the item
263  * \param psz_name a text giving a name or description of the item
264  * \return the new item or NULL on failure
265  */
266 static inline playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
267                                      const char *psz_uri, const char *psz_name )
268 {
269     /* 0 = ITEM_TYPE_UNKNOWN */
270     return playlist_ItemNewWithType( p_obj, psz_uri,  psz_name, 0, NULL, -1,0);
271 }
272
273 #define playlist_ItemNewFromInput(a,b) __playlist_ItemNewFromInput(VLC_OBJECT(a),b)
274 VLC_EXPORT( playlist_item_t *, __playlist_ItemNewFromInput, ( vlc_object_t *p_obj,input_item_t *p_input ) );
275
276 /*************************** Item deletion **************************/
277 VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
278 VLC_EXPORT( int,  playlist_DeleteAllFromInput, ( playlist_t *, int ) );
279 VLC_EXPORT( int,  playlist_DeleteFromInput, ( playlist_t *, int, playlist_item_t *, vlc_bool_t ) );
280 VLC_EXPORT( int,  playlist_DeleteFromItemId, ( playlist_t *, int ) );
281 VLC_EXPORT( int,  playlist_LockDelete, ( playlist_t *, int ) );
282 VLC_EXPORT( int,  playlist_LockDeleteAllFromInput, ( playlist_t *, int ) );
283
284 /*************************** Item fields accessors **************************/
285 VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, const char * ) );
286
287 /******************** Item addition ********************/
288 VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
289 VLC_EXPORT( int,  playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t ) );
290 VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
291 VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
292 VLC_EXPORT( void, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *, playlist_item_t *,int , int ) );
293 VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
294
295 /********************** Misc item operations **********************/
296 VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
297 VLC_EXPORT( playlist_item_t*, playlist_LockItemToNode, (playlist_t *,playlist_item_t *) );
298
299 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
300                                    int i_input_id, playlist_item_t *p_root,
301                                    vlc_bool_t );
302
303 /********************************** Item search *************************/
304 VLC_EXPORT( playlist_item_t *, playlist_ItemGetById, (playlist_t *, int) );
305 VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item_t * ) );
306
307 static inline playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist,
308                                                          int i_id)
309 {
310     playlist_item_t *p_ret;
311     vlc_mutex_lock( &p_playlist->object_lock );
312     p_ret = playlist_ItemGetById( p_playlist, i_id );
313     vlc_mutex_unlock( &p_playlist->object_lock );
314     return p_ret;
315 }
316
317 static inline playlist_item_t *playlist_LockItemGetByInput(
318                                 playlist_t *p_playlist, input_item_t *p_item )
319 {
320     playlist_item_t *p_ret;
321     vlc_mutex_lock( &p_playlist->object_lock );
322     p_ret = playlist_ItemGetByInput( p_playlist, p_item );
323     vlc_mutex_unlock( &p_playlist->object_lock );
324     return p_ret;
325 }
326
327 VLC_EXPORT( int, playlist_LiveSearchUpdate, (playlist_t *, playlist_item_t *, const char *) );
328
329 /********************************************************
330  * Tree management
331  ********************************************************/
332 VLC_EXPORT(void, playlist_NodeDump, ( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ) );
333 VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
334
335 /* Node management */
336 VLC_EXPORT( playlist_item_t *, playlist_NodeCreate, ( playlist_t *, const char *, playlist_item_t * p_parent ) );
337 VLC_EXPORT( int, playlist_NodeAppend, (playlist_t *,playlist_item_t*,playlist_item_t *) );
338 VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,playlist_item_t*,playlist_item_t *, int) );
339 VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
340 VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
341 VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
342 VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
343 VLC_EXPORT( void, playlist_NodesPairCreate, (playlist_t *, const char *, playlist_item_t **, playlist_item_t **, vlc_bool_t ) );
344 VLC_EXPORT( playlist_item_t *, playlist_GetPreferredNode, ( playlist_t *p_playlist, playlist_item_t *p_node ) );
345
346 /***********************************************************************
347  * Inline functions
348  ***********************************************************************/
349 /** Open a playlist file, add its content to the current playlist */
350 static inline int playlist_Import( playlist_t *p_playlist, const char *psz_file){
351     char psz_uri[256+10];
352     input_item_t *p_input;
353     snprintf( psz_uri, 256+9, "file/://%s", psz_file );
354     p_input = input_ItemNewExt( p_playlist, psz_uri, psz_file, 0, NULL, -1 );
355     playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END,
356                        VLC_TRUE );
357     input_Read( p_playlist, p_input, VLC_TRUE );
358     return VLC_SUCCESS;
359 }
360
361 /** Tell if the playlist is currently running */
362 #define playlist_IsPlaying( pl ) ( pl->status.i_status == PLAYLIST_RUNNING )
363
364 /** Tell if the playlist is empty */
365 #define playlist_IsEmpty( pl ) ( pl->items.i_size == 0 )
366
367 /** Tell the number of items in the current playing context */
368 #define playlist_CurrentSize( obj ) obj->p_libvlc->p_playlist->current.i_size
369
370
371 /** Ask the playlist to do some work */
372 static inline void playlist_Signal( playlist_t *p_playlist )
373 {
374     PL_LOCK;
375     vlc_cond_signal( &p_playlist->object_wait );
376     PL_UNLOCK;
377 }
378
379 /**
380  * @}
381  */
382
383 #endif