X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fplaylist%2Fthread.c;h=88036193ac068a34876ce6a0f61c1327e4d17570;hb=0969e58f452d3ad9f36b96122c401f4151c0e45f;hp=f7d8dde733411e4f2d27422cd487f806d719d202;hpb=52157ae334127f4a20b6b4557b09fc44b4a5ed1f;p=vlc diff --git a/src/playlist/thread.c b/src/playlist/thread.c index f7d8dde733..88036193ac 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -36,7 +36,7 @@ /***************************************************************************** * Local prototypes *****************************************************************************/ -static void *Thread ( vlc_object_t * ); +static void *Thread ( void * ); /***************************************************************************** * Main functions for the global thread @@ -66,8 +66,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 +82,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 +102,10 @@ void playlist_Deactivate( playlist_t *p_playlist ) if( p_fetcher ) playlist_fetcher_Delete( p_fetcher ); - /* close the remaining sout-keep */ - if( p_sys->p_sout ) - sout_DeleteInstance( p_sys->p_sout ); - p_sys->p_sout = NULL; + /* release input ressources */ + if( p_sys->p_input_ressource ) + input_ressource_Delete( p_sys->p_input_ressource ); + p_sys->p_input_ressource = NULL; /* */ playlist_MLDump( p_playlist ); @@ -114,22 +118,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 +138,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; @@ -263,7 +252,7 @@ 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_sout ); + input_CreateThreadExtended( p_playlist, p_input, NULL, p_sys->p_input_ressource ); if( p_input_thread ) { @@ -272,7 +261,7 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item ) var_AddCallback( p_input_thread, "intf-event", InputEvent, p_playlist ); } - p_sys->p_sout = NULL; + p_sys->p_input_ressource = NULL; char *psz_uri = input_item_GetURI( p_item->p_input ); if( psz_uri && ( !strncmp( psz_uri, "directory:", 10 ) || @@ -492,14 +481,20 @@ static int LoopInput( playlist_t *p_playlist ) { PL_DEBUG( "dead input" ); - assert( p_sys->p_sout == NULL ); - if( var_CreateGetBool( p_input, "sout-keep" ) ) - p_sys->p_sout = input_DetachSout( p_input ); + assert( p_sys->p_input_ressource == NULL ); + + p_sys->p_input_ressource = input_DetachRessource( 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_ressource_t must be manipulated without playlist lock */ + if( !var_CreateGetBool( p_input, "sout-keep" ) ) + input_ressource_TerminateSout( p_sys->p_input_ressource ); + + /* The DelCallback must be issued without playlist lock */ var_DelCallback( p_input, "intf-event", InputEvent, p_playlist ); + PL_LOCK; p_sys->p_input = NULL; @@ -538,12 +533,28 @@ 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( vlc_object_alive( p_playlist ) ) - vlc_object_wait( p_playlist ); + if( p_sys->p_input_ressource && + input_ressource_HasVout( p_sys->p_input_ressource ) ) + { + /* 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; + + /* input_ressource_t must be manipulated without playlist lock */ + input_ressource_TerminateVout( p_sys->p_input_ressource ); + + PL_LOCK; + } + else + { + if( vlc_object_alive( p_playlist ) ) + vlc_cond_wait( &pl_priv(p_playlist)->signal, + &vlc_internals(p_playlist)->lock ); + } return; } @@ -561,18 +572,17 @@ 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 ); while( vlc_object_alive( p_playlist ) || p_sys->p_input ) @@ -588,13 +598,13 @@ 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( &pl_priv(p_playlist)->signal, + &vlc_internals(p_playlist)->lock ); LoopRequest( p_playlist ); } vlc_object_unlock( p_playlist ); - vlc_restorecancel (canc); return NULL; }