PL_LOCK;
pl_priv(p_playlist)->b_reset_currently_playing = true;
- vlc_object_signal_unlocked( p_playlist );
+ vlc_cond_signal( &pl_priv(p_playlist)->signal );
PL_UNLOCK;
return VLC_SUCCESS;
libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
VariablesInit( p_playlist );
+ vlc_mutex_init( &p->lock );
+ vlc_cond_init( &p->signal );
/* Initialise data structures */
pl_priv(p_playlist)->i_last_playlist_id = 0;
pl_priv(p_playlist)->b_doing_ml = false;
- pl_priv(p_playlist)->b_auto_preparse =
- var_CreateGetBool( p_playlist, "auto-preparse" ) ;
+ const bool b_auto_preparse = var_CreateGetBool( p_playlist, "auto-preparse" );
+ pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
PL_LOCK; /* playlist_NodeCreate will check for it */
p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL,
pl_priv(p_playlist)->b_auto_preparse = false;
playlist_MLLoad( p_playlist );
- pl_priv(p_playlist)->b_auto_preparse = true;
+ pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
vlc_object_set_destructor( p_playlist, playlist_Destructor );
playlist_t *p_playlist = (playlist_t *)p_this;
playlist_private_t *p_sys = pl_priv(p_playlist);
- assert( !p_sys->p_sout );
+ assert( !p_sys->p_input );
+ assert( !p_sys->p_input_resource );
assert( !p_sys->p_preparser );
assert( !p_sys->p_fetcher );
- msg_Err( p_this, "Destroyed" );
-}
-
-/* Input Callback */
-static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
- vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
- VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
- playlist_t *p_playlist = p_data;
-
- if( newval.i_int != INPUT_EVENT_STATE &&
- newval.i_int != INPUT_EVENT_ES )
- return VLC_SUCCESS;
-
- PL_LOCK;
-
- vlc_object_signal_unlocked( p_playlist );
-
- PL_UNLOCK;
- return VLC_SUCCESS;
-}
-
-/* Internals */
-void playlist_release_current_input( playlist_t * p_playlist )
-{
- PL_ASSERT_LOCKED;
-
- if( !pl_priv(p_playlist)->p_input ) return;
-
- input_thread_t * p_input = pl_priv(p_playlist)->p_input;
-
- var_DelCallback( p_input, "intf-event", InputEvent, p_playlist );
- pl_priv(p_playlist)->p_input = NULL;
-
- /* Release the playlist lock, because we may get stuck
- * in vlc_object_release() for some time. */
- PL_UNLOCK;
- vlc_thread_join( p_input );
- vlc_object_release( p_input );
- PL_LOCK;
-}
-
-void playlist_set_current_input(
- playlist_t * p_playlist, input_thread_t * p_input )
-{
- PL_ASSERT_LOCKED;
-
- playlist_release_current_input( p_playlist );
-
- if( p_input )
- {
- vlc_object_hold( p_input );
- pl_priv(p_playlist)->p_input = p_input;
-
- var_AddCallback( p_input, "intf-event", InputEvent, p_playlist );
- }
+ vlc_cond_destroy( &p_sys->signal );
+ vlc_mutex_destroy( &p_sys->lock );
+
+ /* Remove all remaining items */
+ FOREACH_ARRAY( playlist_item_t *p_del, p_playlist->all_items )
+ free( p_del->pp_children );
+ vlc_gc_decref( p_del->p_input );
+ free( p_del );
+ FOREACH_END();
+ ARRAY_RESET( p_playlist->all_items );
+ FOREACH_ARRAY( playlist_item_t *p_del, p_sys->items_to_delete )
+ free( p_del->pp_children );
+ vlc_gc_decref( p_del->p_input );
+ free( p_del );
+ FOREACH_END();
+ ARRAY_RESET( p_sys->items_to_delete );
+
+ ARRAY_RESET( p_playlist->items );
+ ARRAY_RESET( p_playlist->current );
+
+ msg_Dbg( p_this, "Destroyed" );
}
/** Get current playing input.
pl_priv(p_playlist)->status.p_node = p_node;
}
-/**
- * Main loop
- *
- * Main loop for the playlist. It should be entered with the
- * playlist lock (otherwise input event may be lost)
- * \param p_playlist the playlist object
- * \return nothing
- */
-void playlist_MainLoop( playlist_t *p_playlist )
-{
- bool b_playexit = var_GetBool( p_playlist, "play-and-exit" );
-
- PL_ASSERT_LOCKED;
-
- if( pl_priv(p_playlist)->b_reset_currently_playing &&
- mdate() - pl_priv(p_playlist)->last_rebuild_date > 30000 ) // 30 ms
- {
- ResetCurrentlyPlaying( p_playlist, var_GetBool( p_playlist, "random" ),
- get_current_status_item( p_playlist ) );
- pl_priv(p_playlist)->last_rebuild_date = mdate();
- }
-
-check_input:
- /* If there is an input, check that it doesn't need to die. */
- if( pl_priv(p_playlist)->p_input )
- {
- input_thread_t *p_input = pl_priv(p_playlist)->p_input;
-
- if( pl_priv(p_playlist)->request.b_request && !p_input->b_die )
- {
- PL_DEBUG( "incoming request - stopping current input" );
- input_StopThread( p_input );
- }
-
- /* This input is dead. Remove it ! */
- if( p_input->b_dead )
- {
- sout_instance_t **pp_sout = &pl_priv(p_playlist)->p_sout;
-
- PL_DEBUG( "dead input" );
-
- assert( *pp_sout == NULL );
- if( var_CreateGetBool( p_input, "sout-keep" ) )
- *pp_sout = input_DetachSout( p_input );
-
- /* Destroy input */
- playlist_release_current_input( p_playlist );
-
- int i_activity= var_GetInteger( p_playlist, "activity" );
- var_SetInteger( p_playlist, "activity",
- i_activity - DEFAULT_INPUT_ACTIVITY );
- goto check_input;
- }
- /* This input is dying, let it do */
- else if( p_input->b_die )
- {
- PL_DEBUG( "dying input" );
- PL_UNLOCK;
- msleep( INTF_IDLE_SLEEP );
- PL_LOCK;
- goto check_input;
- }
- /* This input has finished, ask it to die ! */
- else if( p_input->b_error || p_input->b_eof )
- {
- PL_DEBUG( "finished input" );
- input_StopThread( p_input );
- /* No need to wait here, we'll wait in the p_input->b_die case */
- goto check_input;
- }
- }
- else
- {
- /* No input. Several cases
- * - No request, running status -> start new item
- * - No request, stopped status -> collect garbage
- * - Request, running requested -> start new item
- * - Request, stopped requested -> collect garbage
- */
- int i_status = pl_priv(p_playlist)->request.b_request ?
- pl_priv(p_playlist)->request.i_status : pl_priv(p_playlist)->status.i_status;
- if( i_status != PLAYLIST_STOPPED )
- {
- msg_Dbg( p_playlist, "starting new item" );
- playlist_item_t *p_item = playlist_NextItem( p_playlist );
-
- if( p_item == NULL )
- {
- msg_Dbg( p_playlist, "nothing to play" );
- pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED;
-
- if( b_playexit == true )
- {
- msg_Info( p_playlist, "end of playlist, exiting" );
- vlc_object_kill( p_playlist->p_libvlc );
- }
- return;
- }
- playlist_PlayItem( p_playlist, p_item );
- /* playlist_PlayItem loose input event, we need to recheck */
- goto check_input;
- }
- else
- {
- pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED;
- }
- }
-}
-
static void VariablesInit( playlist_t *p_playlist )
{
- vlc_value_t val;
/* These variables control updates */
var_Create( p_playlist, "intf-change", VLC_VAR_BOOL );
- val.b_bool = true;
- var_Set( p_playlist, "intf-change", val );
+ var_SetBool( p_playlist, "intf-change", true );
- var_Create( p_playlist, "item-change", VLC_VAR_INTEGER );
- val.i_int = -1;
- var_Set( p_playlist, "item-change", val );
+ var_Create( p_playlist, "item-change", VLC_VAR_ADDRESS );
- var_Create( p_playlist, "item-deleted", VLC_VAR_INTEGER );
- val.i_int = -1;
- var_Set( p_playlist, "item-deleted", val );
+ var_Create( p_playlist, "playlist-item-deleted", VLC_VAR_INTEGER );
+ var_SetInteger( p_playlist, "playlist-item-deleted", -1 );
- var_Create( p_playlist, "item-append", VLC_VAR_ADDRESS );
+ var_Create( p_playlist, "playlist-item-append", VLC_VAR_ADDRESS );
- var_Create( p_playlist, "playlist-current", VLC_VAR_INTEGER );
- val.i_int = -1;
- var_Set( p_playlist, "playlist-current", val );
+ var_Create( p_playlist, "item-current", VLC_VAR_ADDRESS );
+ var_Create( p_playlist, "input-current", VLC_VAR_ADDRESS );
var_Create( p_playlist, "activity", VLC_VAR_INTEGER );
var_SetInteger( p_playlist, "activity", 0 );
var_Create( p_playlist, "album-art", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
}
-int playlist_CurrentId( playlist_t * p_playlist )
-{
- return pl_priv(p_playlist)->status.p_item->i_id;
-
-}
-
-bool playlist_IsPlaying( playlist_t * p_playlist )
-{
- return ( pl_priv(p_playlist)->status.i_status == PLAYLIST_RUNNING &&
- !(pl_priv(p_playlist)->request.b_request && pl_priv(p_playlist)->request.i_status == PLAYLIST_STOPPED) );
-}
-
playlist_item_t * playlist_CurrentPlayingItem( playlist_t * p_playlist )
{
+ PL_ASSERT_LOCKED;
+
return pl_priv(p_playlist)->status.p_item;
}
int playlist_Status( playlist_t * p_playlist )
{
+ PL_ASSERT_LOCKED;
+
return pl_priv(p_playlist)->status.i_status;
}
+