1 /*****************************************************************************
2 * item.c : Playlist item creation/deletion/add/removal functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 #include <vlc_common.h>
30 #include <vlc_playlist.h>
31 #include "playlist_internal.h"
33 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
34 playlist_item_t *p_node, int i_mode, int i_pos );
35 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
36 playlist_item_t *, playlist_item_t * );
37 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item );
38 static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
41 /*****************************************************************************
42 * An input item has gained a subitem (Event Callback)
43 *****************************************************************************/
44 static void input_item_subitem_added( const vlc_event_t * p_event,
47 playlist_item_t *p_parent_playlist_item = user_data;
48 playlist_t * p_playlist = p_parent_playlist_item->p_playlist;
49 input_item_t * p_parent, * p_child;
50 playlist_item_t * p_child_in_category;
51 playlist_item_t * p_item_in_category;
54 p_parent = p_event->p_obj;
55 p_child = p_event->u.input_item_subitem_added.p_new_child;
58 b_play = var_CreateGetBool( p_playlist, "playlist-autostart" );
60 /* This part is really hakish, but this playlist system isn't simple */
61 /* First check if we haven't already added the item as we are
62 * listening using the onelevel and the category representent
63 * (Because of the playlist design) */
64 p_child_in_category = playlist_ItemFindFromInputAndRoot(
65 p_playlist, p_child->i_id,
66 p_playlist->p_root_category,
67 false /* Only non-node */ );
69 if( !p_child_in_category )
71 /* Then, transform to a node if needed */
72 p_item_in_category = playlist_ItemFindFromInputAndRoot(
73 p_playlist, p_parent->i_id,
74 p_playlist->p_root_category,
75 false /* Only non-node */ );
76 if( !p_item_in_category )
78 /* Item may have been removed */
83 b_play = b_play && p_item_in_category == p_playlist->status.p_item;
85 /* If this item is already a node don't transform it */
86 if( p_item_in_category->i_children == -1 )
88 p_item_in_category = playlist_ItemToNode( p_playlist,
89 p_item_in_category, true );
90 p_item_in_category->p_input->i_type = ITEM_TYPE_PLAYLIST;
93 int i_ret = playlist_BothAddInput( p_playlist, p_child,
95 PLAYLIST_APPEND | PLAYLIST_SPREPARSE , PLAYLIST_END,
98 if( i_ret == VLC_SUCCESS && b_play )
100 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
101 true, p_item_in_category, NULL );
109 /*****************************************************************************
110 * An input item's meta or duration has changed (Event Callback)
111 *****************************************************************************/
112 static void input_item_changed( const vlc_event_t * p_event,
116 playlist_item_t * p_item = user_data;
117 var_SetInteger( p_item->p_playlist, "item-change", p_item->i_id );
120 /*****************************************************************************
121 * Listen to vlc_InputItemAddSubItem event
122 *****************************************************************************/
123 static void install_input_item_observer( playlist_item_t * p_item )
125 vlc_event_manager_t * p_em = &p_item->p_input->event_manager;
126 vlc_event_attach( p_em, vlc_InputItemSubItemAdded,
127 input_item_subitem_added, p_item );
128 vlc_event_attach( p_em, vlc_InputItemDurationChanged,
129 input_item_changed, p_item );
130 vlc_event_attach( p_em, vlc_InputItemMetaChanged,
131 input_item_changed, p_item );
134 static void uninstall_input_item_observer( playlist_item_t * p_item )
136 vlc_event_manager_t * p_em = &p_item->p_input->event_manager;
137 vlc_event_detach( p_em, vlc_InputItemMetaChanged,
138 input_item_changed, p_item );
139 vlc_event_detach( p_em, vlc_InputItemDurationChanged,
140 input_item_changed, p_item );
141 vlc_event_detach( p_em, vlc_InputItemSubItemAdded,
142 input_item_subitem_added, p_item );
145 /*****************************************************************************
146 * Playlist item creation
147 *****************************************************************************/
148 playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
150 const char *psz_name,
152 const char *const *ppsz_options,
153 int i_duration, int i_type )
155 input_item_t *p_input;
156 if( psz_uri == NULL ) return NULL;
157 p_input = input_ItemNewWithType( p_obj, psz_uri,
158 psz_name, i_options, ppsz_options,
159 i_duration, i_type );
160 return playlist_ItemNewFromInput( p_obj, p_input );
163 playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
164 input_item_t *p_input )
166 DECMALLOC_NULL( p_item, playlist_item_t );
167 playlist_t *p_playlist = pl_Yield( p_obj );
169 p_item->p_input = p_input;
170 vlc_gc_incref( p_item->p_input );
172 p_item->i_id = ++p_playlist->i_last_playlist_id;
174 p_item->p_parent = NULL;
175 p_item->i_children = -1;
176 p_item->pp_children = NULL;
178 p_item->p_playlist = p_playlist;
180 install_input_item_observer( p_item );
182 pl_Release( p_item->p_playlist );
187 /***************************************************************************
188 * Playlist item destruction
189 ***************************************************************************/
194 * Delete a playlist item and detach its input item
195 * \param p_item item to delete
196 * \return VLC_SUCCESS
198 int playlist_ItemDelete( playlist_item_t *p_item )
200 uninstall_input_item_observer( p_item );
202 vlc_gc_decref( p_item->p_input );
210 * Remove an input item when it appears from a root playlist item
211 * \param p_playlist playlist object
212 * \param i_input_id id of the input to delete
213 * \param p_root root playlist item
214 * \param b_do_stop must stop or not the playlist
215 * \return VLC_SUCCESS or VLC_EGENERIC
217 static int DeleteFromInput( playlist_t *p_playlist, int i_input_id,
218 playlist_item_t *p_root, bool b_do_stop )
221 for( i = 0 ; i< p_root->i_children ; i++ )
223 if( p_root->pp_children[i]->i_children == -1 &&
224 p_root->pp_children[i]->p_input->i_id == i_input_id )
226 DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
229 else if( p_root->pp_children[i]->i_children >= 0 )
231 int i_ret = DeleteFromInput( p_playlist, i_input_id,
232 p_root->pp_children[i], b_do_stop );
233 if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS;
242 * Remove an input item when it appears from a root playlist item
243 * \param p_playlist playlist object
244 * \param i_input_id id of the input to delete
245 * \param p_root root playlist item
246 * \param b_locked TRUE if the playlist is locked
247 * \return VLC_SUCCESS or VLC_EGENERIC
249 int playlist_DeleteInputInParent( playlist_t *p_playlist, int i_input_id,
250 playlist_item_t *p_root, bool b_locked )
253 if( !b_locked ) PL_LOCK;
254 i_ret = DeleteFromInput( p_playlist, i_input_id,
256 if( !b_locked ) PL_UNLOCK;
263 * Remove an input item from ONELEVEL and CATEGORY
264 * \param p_playlist playlist object
265 * \param i_input_id id of the input to delete
266 * \param b_locked TRUE if the playlist is locked
267 * \return VLC_SUCCESS or VLC_ENOITEM
269 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
273 if( !b_locked ) PL_LOCK;
274 i_ret1 = DeleteFromInput( p_playlist, i_input_id,
275 p_playlist->p_root_category, true );
276 i_ret2 = DeleteFromInput( p_playlist, i_input_id,
277 p_playlist->p_root_onelevel, true );
278 if( !b_locked ) PL_UNLOCK;
279 return ( i_ret1 == VLC_SUCCESS || i_ret2 == VLC_SUCCESS ) ?
280 VLC_SUCCESS : VLC_ENOITEM;
286 * \param p_playlist playlist object
287 * \param b_locked TRUE if the playlist is locked
290 void playlist_Clear( playlist_t * p_playlist, bool b_locked )
292 if( !b_locked ) PL_LOCK;
293 playlist_NodeEmpty( p_playlist, p_playlist->p_local_category, true );
294 playlist_NodeEmpty( p_playlist, p_playlist->p_local_onelevel, true );
295 if( !b_locked ) PL_UNLOCK;
299 * Delete playlist item
301 * Remove a playlist item from the playlist, given its id
302 * This function is to be used only by the playlist
303 * \param p_playlist playlist object
304 * \param i_id id of the item do delete
305 * \return VLC_SUCCESS or an error
307 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
309 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
311 if( !p_item ) return VLC_EGENERIC;
312 return DeleteInner( p_playlist, p_item, true );
315 /***************************************************************************
316 * Playlist item addition
317 ***************************************************************************/
321 * Add an item to the playlist or the media library
322 * \param p_playlist the playlist to add into
323 * \param psz_uri the mrl to add to the playlist
324 * \param psz_name a text giving a name or description of this item
325 * \param i_mode the mode used when adding
326 * \param i_pos the position in the playlist where to add. If this is
327 * PLAYLIST_END the item will be added at the end of the playlist
328 * regardless of its size
329 * \param b_playlist TRUE for playlist, FALSE for media library
330 * \param b_locked TRUE if the playlist is locked
331 * \return The id of the playlist item
333 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
334 const char *psz_name, int i_mode, int i_pos,
335 bool b_playlist, bool b_locked )
337 return playlist_AddExt( p_playlist, psz_uri, psz_name,
338 i_mode, i_pos, -1, NULL, 0, b_playlist, b_locked );
342 * Add a MRL into the playlist or the media library, duration and options given
344 * \param p_playlist the playlist to add into
345 * \param psz_uri the mrl to add to the playlist
346 * \param psz_name a text giving a name or description of this item
347 * \param i_mode the mode used when adding
348 * \param i_pos the position in the playlist where to add. If this is
349 * PLAYLIST_END the item will be added at the end of the playlist
350 * regardless of its size
351 * \param i_duration length of the item in milliseconds.
352 * \param ppsz_options an array of options
353 * \param i_options the number of options
354 * \param b_playlist TRUE for playlist, FALSE for media library
355 * \param b_locked TRUE if the playlist is locked
356 * \return The id of the playlist item
358 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
359 const char *psz_name, int i_mode, int i_pos,
360 mtime_t i_duration, const char *const *ppsz_options,
361 int i_options, bool b_playlist, bool b_locked )
364 input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
365 i_options, ppsz_options,
368 i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
370 int i_id = i_ret == VLC_SUCCESS ? p_input->i_id : -1;
372 vlc_gc_decref( p_input );
378 * Add an input item to the playlist node
380 * \param p_playlist the playlist to add into
381 * \param p_input the input item to add
382 * \param i_mode the mode used when adding
383 * \param i_pos the position in the playlist where to add. If this is
384 * PLAYLIST_END the item will be added at the end of the playlist
385 * regardless of its size
386 * \param b_playlist TRUE for playlist, FALSE for media library
387 * \param b_locked TRUE if the playlist is locked
388 * \return VLC_SUCCESS or VLC_ENOMEM or VLC_EGENERIC
390 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
391 int i_mode, int i_pos, bool b_playlist,
394 playlist_item_t *p_item_cat, *p_item_one;
395 if( p_playlist->b_die ) return VLC_EGENERIC;
396 if( !p_playlist->b_doing_ml )
397 PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
400 if( !b_locked ) PL_LOCK;
402 /* Add to ONELEVEL */
403 p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
404 if( p_item_one == NULL ) return VLC_ENOMEM;
405 AddItem( p_playlist, p_item_one,
406 b_playlist ? p_playlist->p_local_onelevel :
407 p_playlist->p_ml_onelevel , i_mode, i_pos );
409 /* Add to CATEGORY */
410 p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
411 if( p_item_cat == NULL ) return VLC_ENOMEM;
412 AddItem( p_playlist, p_item_cat,
413 b_playlist ? p_playlist->p_local_category :
414 p_playlist->p_ml_category , i_mode, i_pos );
416 GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
418 if( !b_locked ) PL_UNLOCK;
425 * Add an input item to p_direct_parent in the category tree, and to the
426 * matching top category in onelevel
427 * \param p_playlist the playlist to add into
428 * \param p_input the input item to add
429 * \param p_direct_parent the parent item to add into
430 * \param i_mode the mode used when adding
431 * \param i_pos the position in the playlist where to add. If this is
432 * PLAYLIST_END the item will be added at the end of the playlist
433 * regardless of its size
434 * \param i_cat id of the items category
435 * \param i_one id of the item onelevel category
436 * \param b_locked TRUE if the playlist is locked
437 * \return VLC_SUCCESS if success, VLC_EGENERIC if fail, VLC_ENOMEM if OOM
439 int playlist_BothAddInput( playlist_t *p_playlist,
440 input_item_t *p_input,
441 playlist_item_t *p_direct_parent,
442 int i_mode, int i_pos,
443 int *i_cat, int *i_one, bool b_locked )
445 playlist_item_t *p_item_cat, *p_item_one, *p_up;
448 if( p_playlist->b_die ) return VLC_EGENERIC;
449 if( !b_locked ) PL_LOCK;
451 /* Add to category */
452 p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
453 if( p_item_cat == NULL ) return VLC_ENOMEM;
454 AddItem( p_playlist, p_item_cat, p_direct_parent, i_mode, i_pos );
456 /* Add to onelevel */
457 /**Â \todo make a faster case for ml import */
458 p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
459 if( p_item_one == NULL ) return VLC_ENOMEM;
461 p_up = p_direct_parent;
462 while( p_up->p_parent != p_playlist->p_root_category )
464 p_up = p_up->p_parent;
466 for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
468 if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id ==
469 p_up->p_input->i_id )
471 AddItem( p_playlist, p_item_one,
472 p_playlist->p_root_onelevel->pp_children[i_top],
477 GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
479 if( i_cat ) *i_cat = p_item_cat->i_id;
480 if( i_one ) *i_one = p_item_one->i_id;
482 if( !b_locked ) PL_UNLOCK;
487 * Add an input item to a given node
489 * \param p_playlist the playlist to add into
490 * \param p_input the input item to add
491 * \param p_parent the parent item to add into
492 * \param i_mode the mode used when addin
493 * \param i_pos the position in the playlist where to add. If this is
494 * PLAYLIST_END the item will be added at the end of the playlist
495 * regardless of its size
496 * \param b_locked TRUE if the playlist is locked
497 * \return the new playlist item
499 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
500 input_item_t *p_input,
501 playlist_item_t *p_parent,
502 int i_mode, int i_pos,
505 playlist_item_t *p_item;
507 assert( p_parent && p_parent->i_children != -1 );
509 if( p_playlist->b_die )
511 if( !b_locked ) PL_LOCK;
513 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
514 if( p_item == NULL ) return NULL;
515 AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
517 if( !b_locked ) PL_UNLOCK;
522 /*****************************************************************************
523 * Playlist item misc operations
524 *****************************************************************************/
529 * Transform an item to a node. Return the node in the category tree, or NULL
531 * This function must be entered without the playlist lock
532 * \param p_playlist the playlist object
533 * \param p_item the item to transform
534 * \param b_locked TRUE if the playlist is locked
535 * \return the item transform in a node
537 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
538 playlist_item_t *p_item,
542 playlist_item_t *p_item_in_category;
544 * Find the input in CATEGORY.
546 * - change it to node
547 * - we'll return it at the end
548 * - If we are a direct child of onelevel root, change to node, else
549 * delete the input from ONELEVEL
550 * - If we don't find it, just change to node (we are probably in VLM)
553 * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
554 * useful for later BothAddInput )
557 if( !b_locked ) PL_LOCK;
559 /* Fast track the media library, no time to loose */
560 if( p_item == p_playlist->p_ml_category ) {
561 if( !b_locked ) PL_UNLOCK;
565 /** \todo First look if we don't already have it */
566 p_item_in_category = playlist_ItemFindFromInputAndRoot(
567 p_playlist, p_item->p_input->i_id,
568 p_playlist->p_root_category,
571 if( p_item_in_category )
573 playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
574 p_playlist, p_item->p_input->i_id,
575 p_playlist->p_root_onelevel,
577 assert( p_item_in_one );
579 /* We already have it, and there is nothing more to do */
580 ChangeToNode( p_playlist, p_item_in_category );
582 /* Item in one is a root, change it to node */
583 if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
584 ChangeToNode( p_playlist, p_item_in_one );
587 DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
588 p_playlist->p_root_onelevel, false );
590 p_playlist->b_reset_currently_playing = true;
591 vlc_cond_signal( &p_playlist->object_wait );
592 var_SetInteger( p_playlist, "item-change", p_item_in_category->
594 if( !b_locked ) PL_UNLOCK;
595 return p_item_in_category;
599 ChangeToNode( p_playlist, p_item );
600 if( !b_locked ) PL_UNLOCK;
606 * Find an item within a root, given its input id.
608 * \param p_playlist the playlist object
609 * \param i_input_id id of the input
610 * \param p_root root playlist item
611 * \param b_items_only TRUE if we want the item himself
612 * \return the first found item, or NULL if not found
614 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
616 playlist_item_t *p_root,
620 for( i = 0 ; i< p_root->i_children ; i++ )
622 if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) &&
623 p_root->pp_children[i]->p_input->i_id == i_input_id )
625 return p_root->pp_children[i];
627 else if( p_root->pp_children[i]->i_children >= 0 )
629 playlist_item_t *p_search =
630 playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
631 p_root->pp_children[i],
633 if( p_search ) return p_search;
640 static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item,
641 playlist_item_t *p_node, int i_newpos )
644 playlist_item_t *p_detach = p_item->p_parent;
647 if( p_node->i_children == -1 ) return VLC_EGENERIC;
649 for( j = 0; j < p_detach->i_children; j++ )
651 if( p_detach->pp_children[j] == p_item ) break;
653 REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
655 /* Attach to new parent */
656 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
657 p_item->p_parent = p_node;
665 * This function must be entered with the playlist lock
667 * \param p_playlist the playlist
668 * \param p_item the item to move
669 * \param p_node the new parent of the item
670 * \param i_newpos the new position under this new parent
671 * \return VLC_SUCCESS or an error
673 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
674 playlist_item_t *p_node, int i_newpos )
677 /* Drop on a top level node. Move in the two trees */
678 if( p_node->p_parent == p_playlist->p_root_category ||
679 p_node->p_parent == p_playlist->p_root_onelevel )
681 /* Fixme: avoid useless lookups but we need some clean helpers */
683 /* Fixme: if we try to move a node on a top-level node, it will
684 * fail because the node doesn't exist in onelevel and we will
685 * do some shit in onelevel. We should recursively move all items
687 playlist_item_t *p_node_onelevel;
688 playlist_item_t *p_item_onelevel;
689 p_node_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
690 p_node->p_input->i_id,
691 p_playlist->p_root_onelevel,
693 p_item_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
694 p_item->p_input->i_id,
695 p_playlist->p_root_onelevel,
697 if( p_node_onelevel && p_item_onelevel )
698 TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, 0 );
701 playlist_item_t *p_node_category;
702 playlist_item_t *p_item_category;
703 p_node_category = playlist_ItemFindFromInputAndRoot( p_playlist,
704 p_node->p_input->i_id,
705 p_playlist->p_root_category,
707 p_item_category = playlist_ItemFindFromInputAndRoot( p_playlist,
708 p_item->p_input->i_id,
709 p_playlist->p_root_category,
711 if( p_node_category && p_item_category )
712 TreeMove( p_playlist, p_item_category, p_node_category, 0 );
717 i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos );
718 p_playlist->b_reset_currently_playing = true;
719 vlc_cond_signal( &p_playlist->object_wait );
724 * Send a notification that an item has been added to a node
726 * \param p_playlist the playlist object
727 * \param i_item_id id of the item added
728 * \param i_node_id id of the node in wich the item was added
729 * \param b_signal TRUE if the function must send a signal
732 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
733 int i_node_id, bool b_signal )
736 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t) );
740 p_add->i_item = i_item_id;
741 p_add->i_node = i_node_id;
742 val.p_address = p_add;
743 p_playlist->b_reset_currently_playing = true;
745 vlc_cond_signal( &p_playlist->object_wait );
746 var_Set( p_playlist, "item-append", val );
750 /*****************************************************************************
751 * Playlist item accessors
752 *****************************************************************************/
755 * Set the name of a playlist item
757 * \param p_item the item
758 * \param psz_name the name
759 * \return VLC_SUCCESS or VLC_EGENERIC
761 int playlist_ItemSetName( playlist_item_t *p_item, const char *psz_name )
763 if( psz_name && p_item )
765 input_item_SetName( p_item->p_input, psz_name );
771 /***************************************************************************
772 * The following functions are local
773 ***************************************************************************/
775 /* Enqueue an item for preparsing, and play it, if needed */
776 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
777 playlist_item_t *p_item_cat,
778 playlist_item_t *p_item_one )
780 if( (i_mode & PLAYLIST_GO ) )
782 playlist_item_t *p_parent = p_item_one;
783 playlist_item_t *p_toplay = NULL;
786 if( p_parent == p_playlist->p_root_category )
788 p_toplay = p_item_cat; break;
790 else if( p_parent == p_playlist->p_root_onelevel )
792 p_toplay = p_item_one; break;
794 p_parent = p_parent->p_parent;
797 p_playlist->request.b_request = true;
798 p_playlist->request.i_skip = 0;
799 p_playlist->request.p_item = p_toplay;
800 if( p_playlist->p_input )
801 input_StopThread( p_playlist->p_input );
802 p_playlist->request.i_status = PLAYLIST_RUNNING;
803 vlc_cond_signal( &p_playlist->object_wait );
805 /* Preparse if PREPARSE or SPREPARSE & not enough meta */
806 char *psz_artist = input_item_GetArtist( p_item_cat->p_input );
807 char *psz_album = input_item_GetAlbum( p_item_cat->p_input );
808 if( p_playlist->b_auto_preparse &&
809 (i_mode & PLAYLIST_PREPARSE ||
810 ( i_mode & PLAYLIST_SPREPARSE &&
811 ( EMPTY_STR( psz_artist ) || ( EMPTY_STR( psz_album ) ) )
813 playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
814 /* If we already have it, signal it */
815 else if( !EMPTY_STR( psz_artist ) && !EMPTY_STR( psz_album ) )
816 input_item_SetPreparsed( p_item_cat->p_input, true );
821 /* Add the playlist item to the requested node and fire a notification */
822 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
823 playlist_item_t *p_node, int i_mode, int i_pos )
825 ARRAY_APPEND(p_playlist->items, p_item);
826 ARRAY_APPEND(p_playlist->all_items, p_item);
828 if( i_pos == PLAYLIST_END )
829 playlist_NodeAppend( p_playlist, p_item, p_node );
831 playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
833 if( !p_playlist->b_doing_ml )
834 playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id,
835 !( i_mode & PLAYLIST_NO_REBUILD ) );
838 /* Actually convert an item to a node */
839 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
842 if( p_item->i_children == -1 )
843 p_item->i_children = 0;
845 /* Remove it from the array of available items */
846 ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
848 ARRAY_REMOVE( p_playlist->items, i );
851 /* Do the actual removal */
852 static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
856 int i_id = p_item->i_id;
857 bool b_delay_deletion = false;
859 if( p_item->i_children > -1 )
861 return playlist_NodeDelete( p_playlist, p_item, true, false );
863 p_playlist->b_reset_currently_playing = true;
864 var_SetInteger( p_playlist, "item-deleted", i_id );
866 /* Remove the item from the bank */
867 ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
869 ARRAY_REMOVE( p_playlist->all_items, i );
871 ARRAY_BSEARCH( p_playlist->items,->i_id, int, i_id, i );
873 ARRAY_REMOVE( p_playlist->items, i );
875 /* Check if it is the current item */
876 if( p_playlist->status.p_item == p_item )
878 /* Hack we don't call playlist_Control for lock reasons */
881 p_playlist->request.i_status = PLAYLIST_STOPPED;
882 p_playlist->request.b_request = true;
883 p_playlist->request.p_item = NULL;
884 msg_Info( p_playlist, "stopping playback" );
885 vlc_cond_signal( &p_playlist->object_wait );
887 b_delay_deletion = true;
890 PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
892 /* Remove the item from its parent */
893 playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
895 if( !b_delay_deletion )
896 playlist_ItemDelete( p_item );
899 PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item ) );
900 p_item->i_flags |= PLAYLIST_REMOVE_FLAG;