-void PreparseEnqueueItemSub( playlist_t *p_playlist,
- playlist_item_t *p_item )
-{
- int i;
- if( p_item->i_children == -1 )
- {
- vlc_gc_incref( p_item );
- INSERT_ELEM( p_playlist->p_preparse->pp_waiting,
- p_playlist->p_preparse->i_waiting,
- p_playlist->p_preparse->i_waiting,
- p_item->p_input );
- }
- else
- {
- for( i = 0; i < p_item->i_children; i++)
- {
- PreparseEnqueueItemSub( p_playlist,
- p_item->pp_children[i] );
- }
- }
-}
-
-/*****************************************************************************
- * Playback logic
- *****************************************************************************/
-
-/** This function calculates the next playlist item, depending
- * on the playlist course mode (forward, backward, random, view,...). */
-playlist_item_t * playlist_NextItem( playlist_t *p_playlist )
-{
- playlist_item_t *p_new = NULL;
- int i_skip,i;
-
- vlc_bool_t b_loop = var_GetBool( p_playlist, "loop" );
- vlc_bool_t b_random = var_GetBool( p_playlist, "random" );
- vlc_bool_t b_repeat = var_GetBool( p_playlist, "repeat" );
- vlc_bool_t b_playstop = var_GetBool( p_playlist, "play-and-stop" );
-
- /* Handle quickly a few special cases */
-
- /* No items to play */
- if( p_playlist->i_size == 0 )
- {
- msg_Info( p_playlist, "playlist is empty" );
- return NULL;
- }
-
- /* Repeat and play/stop */
- if( !p_playlist->request.b_request && b_repeat == VLC_TRUE &&
- p_playlist->status.p_item )
- {
- msg_Dbg( p_playlist,"repeating item" );
- return p_playlist->status.p_item;
- }
- if( !p_playlist->request.b_request && b_playstop == VLC_TRUE )
- {
- msg_Dbg( p_playlist,"stopping (play and stop)");
- return NULL;
- }
-
- if( !p_playlist->request.b_request && p_playlist->status.p_item &&
- p_playlist->status.p_item->i_flags & PLAYLIST_SKIP_FLAG )
- {
- msg_Dbg( p_playlist, "blocking item, stopping") ;
- return NULL;
- }
-
- /* Random case. This is an exception: if request, but request is skip +- 1
- * we don't go to next item but select a new random one. */
- if( b_random )
- msg_Err( p_playlist, "random unsupported" );
-#if 0
- &&
- ( !p_playlist->request.b_request ||
- ( p_playlist->request.b_request && ( p_playlist->request.p_item == NULL ||
- p_playlist->request.i_skip == 1 || p_playlist->request.i_skip == -1 ) ) ) )
- {
- /* how many items to choose from ? */
- i_count = 0;
- for ( i = 0; i < p_playlist->i_size; i++ )
- {
- if ( p_playlist->pp_items[i]->p_input->i_nb_played == 0 )
- i_count++;
- }
- /* Nothing left? */
- if ( i_count == 0 )
- {
- /* Don't loop? Exit! */
- if( !b_loop )
- return NULL;
- /* Otherwise reset the counter */
- for ( i = 0; i < p_playlist->i_size; i++ )
- {
- p_playlist->pp_items[i]->p_input->i_nb_played = 0;
- }
- i_count = p_playlist->i_size;
- }
- srand( (unsigned int)mdate() );
- i = rand() % i_count + 1 ;
- /* loop thru the list and count down the unplayed items to the selected one */
- for ( i_new = 0; i_new < p_playlist->i_size && i > 0; i_new++ )
- {
- if ( p_playlist->pp_items[i_new]->p_input->i_nb_played == 0 )
- i--;
- }
- i_new--;
-
- p_playlist->request.i_skip = 0;
- p_playlist->request.b_request = VLC_FALSE;
- return p_playlist->pp_items[i_new];
- }
-#endif
-
- /* Start the real work */
- if( p_playlist->request.b_request )
- {
-#ifdef PLAYLIST_DEBUG
- msg_Dbg( p_playlist,"processing request" );
-#endif
- p_new = p_playlist->request.p_item;
- i_skip = p_playlist->request.i_skip;
-
- p_playlist->status.p_node = p_playlist->request.p_node;
-
- /* If we are asked for a node, take its first item */
- if( i_skip == 0 &&
- ( p_new == NULL || p_new->i_children != -1 ) )
- {
- i_skip++;
- }
-
- if( i_skip > 0 )
- {
- for( i = i_skip; i > 0 ; i-- )
- {
- p_new = playlist_GetNextEnabledLeaf( p_playlist,
- p_playlist->request.p_node,
- p_new );
- if( p_new == NULL )
- {
-#ifdef PLAYLIST_DEBUG
- msg_Dbg( p_playlist, "looping - restarting at beginning "
- "of node" );
-#endif
- p_new = playlist_GetNextLeaf( p_playlist,
- p_playlist->request.p_node,
- NULL );
- if( p_new == NULL ) break;
- }
- }
- }
- else if( i_skip < 0 )
- {
- for( i = i_skip; i < 0 ; i++ )
- {
- p_new = playlist_GetPrevLeaf( p_playlist,
- p_playlist->request.p_node,
- p_new );
- if( p_new == NULL )
- {
-#ifdef PLAYLIST_DEBUG
- msg_Dbg( p_playlist, "looping - restarting at end "
- "of node" );
-#endif
- /** \bug This is needed because GetPrevLeaf does not loop
- * by itself */
- p_new = playlist_GetLastLeaf( p_playlist,
- p_playlist->request.p_node );
- }
- if( p_new == NULL ) break;
- }
- }
- /* Clear the request */
- p_playlist->request.b_request = VLC_FALSE;
- }
- /* "Automatic" item change ( next ) */
- else
- {
-#ifdef PLAYLIST_DEBUG
- msg_Dbg( p_playlist,"changing item without a request" );
-#endif
- /* Cant go to next from current item */
- if( p_playlist->status.p_item &&
- p_playlist->status.p_item->i_flags & PLAYLIST_SKIP_FLAG )
- return NULL;
-
- p_new = playlist_GetNextLeaf( p_playlist,
- p_playlist->status.p_node,
- p_playlist->status.p_item );
- if( p_new == NULL && b_loop )
- {
-#ifdef PLAYLIST_DEBUG
- msg_Dbg( p_playlist, "looping" );
-#endif
- p_new = playlist_GetNextLeaf( p_playlist,
- p_playlist->status.p_node,
- NULL );
- }
- /* The new item can't be autoselected */
- if( p_new != NULL && p_new->i_flags & PLAYLIST_SKIP_FLAG )
- return NULL;
- }
- if( p_new == NULL )
- {
- msg_Dbg( p_playlist, "did not find something to play" );
- }
- return p_new;