X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fplaylist%2Fthread.c;h=267d00e876b69dce01ce65e16fae86887621fc10;hb=6920054e55c4a2c707273efc9b59cfd81c4596b2;hp=4763823f395b94211efc58f4db2e0dd9a837a96a;hpb=c884cebcaca04bf53b9bba8181f08d6dcfb5cb16;p=vlc diff --git a/src/playlist/thread.c b/src/playlist/thread.c index 4763823f39..267d00e876 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -25,6 +25,8 @@ # include "config.h" #endif +#include + #include #include #include @@ -36,7 +38,7 @@ /***************************************************************************** * Local prototypes *****************************************************************************/ -static void *Thread ( vlc_object_t * ); +static void *Thread ( void * ); /***************************************************************************** * Main functions for the global thread @@ -66,8 +68,8 @@ void playlist_Activate( playlist_t *p_playlist ) msg_Err( p_playlist, "cannot create playlist preparser" ); /* Start the playlist thread */ - if( vlc_thread_create( p_playlist, "playlist", Thread, - VLC_THREAD_PRIORITY_LOW, false ) ) + if( vlc_clone( &p_sys->thread, Thread, p_playlist, + VLC_THREAD_PRIORITY_LOW ) ) { msg_Err( p_playlist, "cannot spawn playlist thread" ); } @@ -82,7 +84,11 @@ void playlist_Deactivate( playlist_t *p_playlist ) msg_Dbg( p_playlist, "Deactivate" ); vlc_object_kill( p_playlist ); - vlc_thread_join( p_playlist ); + PL_LOCK; + vlc_cond_signal( &p_sys->signal ); + PL_UNLOCK; + + vlc_join( p_sys->thread, NULL ); assert( !p_sys->p_input ); PL_LOCK; @@ -98,10 +104,10 @@ void playlist_Deactivate( playlist_t *p_playlist ) if( p_fetcher ) playlist_fetcher_Delete( p_fetcher ); - /* release input ressources */ - if( p_sys->p_input_ressource ) - input_ressource_Delete( p_sys->p_input_ressource ); - p_sys->p_input_ressource = NULL; + /* release input resources */ + if( p_sys->p_input_resource ) + input_resource_Delete( p_sys->p_input_resource ); + p_sys->p_input_resource = NULL; /* */ playlist_MLDump( p_playlist ); @@ -114,22 +120,6 @@ void playlist_Deactivate( playlist_t *p_playlist ) /* Release the current item */ set_current_status_item( p_playlist, NULL ); - 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 ); - PL_UNLOCK; msg_Dbg( p_playlist, "Deactivated" ); @@ -150,7 +140,8 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd, PL_LOCK; - vlc_object_signal_unlocked( p_playlist ); + /* XXX: signaling while not changing any parameter... suspicious... */ + vlc_cond_signal( &pl_priv(p_playlist)->signal ); PL_UNLOCK; return VLC_SUCCESS; @@ -262,17 +253,22 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item ) assert( p_sys->p_input == NULL ); - input_thread_t *p_input_thread = - input_CreateThreadExtended( p_playlist, p_input, NULL, p_sys->p_input_ressource ); - + input_thread_t *p_input_thread = input_Create( p_playlist, p_input, NULL, p_sys->p_input_resource ); if( p_input_thread ) { p_sys->p_input = p_input_thread; - var_AddCallback( p_input_thread, "intf-event", InputEvent, p_playlist ); + + var_SetAddress( p_playlist, "input-current", p_input_thread ); + + if( input_Start( p_sys->p_input ) ) + { + vlc_object_release( p_input_thread ); + p_sys->p_input = p_input_thread = NULL; + } } - p_sys->p_input_ressource = NULL; + p_sys->p_input_resource = NULL; char *psz_uri = input_item_GetURI( p_item->p_input ); if( psz_uri && ( !strncmp( psz_uri, "directory:", 10 ) || @@ -305,7 +301,7 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item ) } PL_UNLOCK; - var_SetInteger( p_playlist, "playlist-current", p_input->i_id ); + var_SetAddress( p_playlist, "item-current", p_input ); PL_LOCK; return VLC_SUCCESS; @@ -484,7 +480,7 @@ static int LoopInput( playlist_t *p_playlist ) if( ( p_sys->request.b_request || !vlc_object_alive( p_playlist ) ) && !p_input->b_die ) { PL_DEBUG( "incoming request - stopping current input" ); - input_StopThread( p_input ); + input_Stop( p_input, true ); } /* This input is dead. Remove it ! */ @@ -492,16 +488,20 @@ static int LoopInput( playlist_t *p_playlist ) { PL_DEBUG( "dead input" ); - assert( p_sys->p_input_ressource == NULL ); + assert( p_sys->p_input_resource == NULL ); - p_sys->p_input_ressource = input_DetachRessource( p_input ); - if( !var_CreateGetBool( p_input, "sout-keep" ) ) - input_ressource_TerminateSout( p_sys->p_input_ressource ); + p_sys->p_input_resource = input_DetachResource( p_input ); - /* The DelCallback must be issued without playlist lock - * It is not a problem as we return VLC_EGENERIC */ PL_UNLOCK; + /* We can unlock as we return VLC_EGENERIC (no event will be lost) */ + + /* input_resource_t must be manipulated without playlist lock */ + if( !var_CreateGetBool( p_input, "sout-keep" ) ) + input_resource_TerminateSout( p_sys->p_input_resource ); + + /* The DelCallback must be issued without playlist lock */ var_DelCallback( p_input, "intf-event", InputEvent, p_playlist ); + PL_LOCK; p_sys->p_input = NULL; @@ -521,7 +521,7 @@ static int LoopInput( playlist_t *p_playlist ) else if( p_input->b_error || p_input->b_eof ) { PL_DEBUG( "finished input" ); - input_StopThread( p_input ); + input_Stop( p_input, false ); } return VLC_SUCCESS; } @@ -540,15 +540,27 @@ static void LoopRequest( playlist_t *p_playlist ) const int i_status = p_sys->request.b_request ? p_sys->request.i_status : p_sys->status.i_status; - if( i_status == PLAYLIST_STOPPED ) + if( i_status == PLAYLIST_STOPPED || !vlc_object_alive( p_playlist ) ) { p_sys->status.i_status = PLAYLIST_STOPPED; - if( p_sys->p_input_ressource ) - input_ressource_TerminateVout( p_sys->p_input_ressource ); + if( p_sys->p_input_resource && + input_resource_HasVout( p_sys->p_input_resource ) ) + { + /* XXX We can unlock if we don't issue the wait as we will be + * call again without anything else done between the calls */ + PL_UNLOCK; - if( vlc_object_alive( p_playlist ) ) - vlc_object_wait( p_playlist ); + /* input_resource_t must be manipulated without playlist lock */ + input_resource_TerminateVout( p_sys->p_input_resource ); + + PL_LOCK; + } + else + { + if( vlc_object_alive( p_playlist ) ) + vlc_cond_wait( &p_sys->signal, &p_sys->lock ); + } return; } @@ -566,20 +578,19 @@ static void LoopRequest( playlist_t *p_playlist ) if( var_GetBool( p_playlist, "play-and-exit" ) ) { msg_Info( p_playlist, "end of playlist, exiting" ); - vlc_object_kill( p_playlist->p_libvlc ); + libvlc_Quit( p_playlist->p_libvlc ); } } /** * Run the main control thread itself */ -static void *Thread ( vlc_object_t *p_this ) +static void *Thread ( void *data ) { - playlist_t *p_playlist = (playlist_t*)p_this; + playlist_t *p_playlist = data; playlist_private_t *p_sys = pl_priv(p_playlist); - int canc = vlc_savecancel(); - vlc_object_lock( p_playlist ); + playlist_Lock( p_playlist ); while( vlc_object_alive( p_playlist ) || p_sys->p_input ) { /* FIXME: what's that ! */ @@ -593,13 +604,12 @@ static void *Thread ( vlc_object_t *p_this ) /* If there is an input, check that it doesn't need to die. */ while( !LoopInput( p_playlist ) ) - vlc_object_wait( p_playlist ); + vlc_cond_wait( &p_sys->signal, &p_sys->lock ); LoopRequest( p_playlist ); } - vlc_object_unlock( p_playlist ); + playlist_Unlock( p_playlist ); - vlc_restorecancel (canc); return NULL; }