diff --git a/include/vlc_input.h b/include/vlc_input.h index a119c023e8cd680e3fe6f36ac9509a5f2a8feb61..4bac4d5a4acbfea0792890d0d3268d24e82180a8 100644 --- a/include/vlc_input.h +++ b/include/vlc_input.h @@ -375,6 +375,8 @@ typedef enum input_event_type_e INPUT_EVENT_STATE, /* b_dead is true */ INPUT_EVENT_DEAD, + /* a *user* abort has been requested */ + INPUT_EVENT_ABORT, /* "rate" has changed */ INPUT_EVENT_RATE, @@ -435,12 +437,22 @@ typedef enum input_event_type_e * Prototypes *****************************************************************************/ -/* input_CreateThread - * Release the returned input_thread_t using vlc_object_release() */ +/** + * It will create a new input thread. + * + * You must call input_StopThread() on it and then vlc_object_release(). + */ #define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b) VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) ); -VLC_EXPORT( void, input_StopThread, ( input_thread_t * ) ); +/** + * It will ask a input_thread_t to stop. + * + * b_abort must be true when a user stop is requested and not because you have + * detected an error or an eof. It will be used to properly send the + * INPUT_EVENT_ABORT event. + */ +VLC_EXPORT( void, input_StopThread, ( input_thread_t *, bool b_abort ) ); #define input_Read(a,b,c) __input_Read(VLC_OBJECT(a),b, c) VLC_EXPORT( int, __input_Read, ( vlc_object_t *, input_item_t *, bool ) ); diff --git a/modules/services_discovery/podcast.c b/modules/services_discovery/podcast.c index e716731b1ebdf301e886d3716cda740eb3a0650c..6d12d8a89675e2c67ee81f16d4cc2f114f7496a2 100644 --- a/modules/services_discovery/podcast.c +++ b/modules/services_discovery/podcast.c @@ -158,7 +158,7 @@ static void Close( vlc_object_t *p_this ) { if( p_sd->p_sys->pp_input[i] ) { - input_StopThread( p_sd->p_sys->pp_input[i] ); + input_StopThread( p_sd->p_sys->pp_input[i], true ); vlc_object_release( p_sd->p_sys->pp_input[i] ); p_sd->p_sys->pp_input[i] = NULL; } @@ -197,7 +197,7 @@ static void *Run( void *data ) if( p_sd->p_sys->pp_input[i]->b_eof || p_sd->p_sys->pp_input[i]->b_error ) { - input_StopThread( p_sd->p_sys->pp_input[i] ); + input_StopThread( p_sd->p_sys->pp_input[i], false ); vlc_object_release( p_sd->p_sys->pp_input[i] ); p_sd->p_sys->pp_input[i] = NULL; REMOVE_ELEM( p_sys->pp_input, p_sys->i_input, i ); diff --git a/src/control/media_player.c b/src/control/media_player.c index b2ee0962012b2be6df0235c49a91c01444d2826e..cdc85e66aa09df6754720152e56ac74438444d15 100644 --- a/src/control/media_player.c +++ b/src/control/media_player.c @@ -69,7 +69,7 @@ static inline libvlc_state_t vlc_to_libvlc_state( int vlc_state ) * * Object lock is NOT held. */ -static void release_input_thread( libvlc_media_player_t *p_mi ) +static void release_input_thread( libvlc_media_player_t *p_mi, bool b_input_abort ) { input_thread_t * p_input_thread; @@ -89,7 +89,7 @@ static void release_input_thread( libvlc_media_player_t *p_mi ) input_event_changed, p_mi ); /* We owned this one */ - input_StopThread( p_input_thread ); + input_StopThread( p_input_thread, b_input_abort ); vlc_thread_join( p_input_thread ); var_Destroy( p_input_thread, "drawable-hwnd" ); @@ -455,7 +455,7 @@ void libvlc_media_player_release( libvlc_media_player_t *p_mi ) vlc_mutex_unlock( &p_mi->object_lock ); vlc_mutex_destroy( &p_mi->object_lock ); - release_input_thread( p_mi ); + release_input_thread( p_mi, true ); libvlc_event_manager_release( p_mi->p_event_manager ); @@ -494,7 +494,12 @@ void libvlc_media_player_set_media( vlc_mutex_lock( &p_mi->object_lock ); - release_input_thread( p_mi ); + /* FIXME I am not sure if it is a user request or on die(eof/error) + * request here */ + release_input_thread( p_mi, + p_mi->p_input_thread && + !p_mi->p_input_thread->b_eof && + !p_mi->p_input_thread->b_error ); if( p_mi->p_md ) libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, p_e ); @@ -703,7 +708,7 @@ void libvlc_media_player_stop( libvlc_media_player_t *p_mi, if( p_mi->b_own_its_input_thread ) { vlc_mutex_lock( &p_mi->object_lock ); - release_input_thread( p_mi ); /* This will stop the input thread */ + release_input_thread( p_mi, true ); /* This will stop the input thread */ vlc_mutex_unlock( &p_mi->object_lock ); } else @@ -713,7 +718,7 @@ void libvlc_media_player_stop( libvlc_media_player_t *p_mi, if( !p_input_thread ) return; - input_StopThread( p_input_thread ); + input_StopThread( p_input_thread, true ); vlc_object_release( p_input_thread ); } } diff --git a/src/input/event.c b/src/input/event.c index ddef8fd081a888d4e6bc420418e83ab185b55455..242bf1fd01b61e6bf5c45f7fd9deb58499abe022 100644 --- a/src/input/event.c +++ b/src/input/event.c @@ -55,6 +55,10 @@ void input_SendEventDead( input_thread_t *p_input ) Trigger( p_input, INPUT_EVENT_DEAD ); } +void input_SendEventAbort( input_thread_t *p_input ) +{ + Trigger( p_input, INPUT_EVENT_ABORT ); +} void input_SendEventTimes( input_thread_t *p_input, double f_position, mtime_t i_time, mtime_t i_length ) diff --git a/src/input/event.h b/src/input/event.h index 1116c5c116e440b1fe553889f891cdf251a667df..b6ed2bfc607af1652b0f7645278da43af2526bc5 100644 --- a/src/input/event.h +++ b/src/input/event.h @@ -34,6 +34,7 @@ * Event for input.c *****************************************************************************/ void input_SendEventDead( input_thread_t *p_input ); +void input_SendEventAbort( input_thread_t *p_input ); void input_SendEventTimes( input_thread_t *p_input, double f_position, mtime_t i_time, mtime_t i_length ); void input_SendEventStatistics( input_thread_t *p_input ); void input_SendEventRate( input_thread_t *p_input, int i_rate ); diff --git a/src/input/input.c b/src/input/input.c index bdf91af2bceadf26fbf01a36793504aaa64167a1..b504da71c374de6c152c338b9a1fd562b10e21a6 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -430,7 +430,7 @@ int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item ) * * \param the input thread to stop */ -void input_StopThread( input_thread_t *p_input ) +void input_StopThread( input_thread_t *p_input, bool b_abort ) { /* Set die for input and ALL of this childrens (even (grand-)grand-childrens) * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to @@ -438,6 +438,8 @@ void input_StopThread( input_thread_t *p_input ) ObjectKillChildrens( p_input, VLC_OBJECT(p_input) ); input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL ); + if( b_abort ) + input_SendEventAbort( p_input ); } input_resource_t *input_DetachResource( input_thread_t *p_input ) diff --git a/src/input/vlm.c b/src/input/vlm.c index d611eb86a66e0230d511d42268331f4a9a0e306c..23e6004346bdba3c27e9d1caa73a5b1782ae9acd 100644 --- a/src/input/vlm.c +++ b/src/input/vlm.c @@ -536,7 +536,7 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media ) while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 ); - input_StopThread( p_input ); + input_StopThread( p_input, false ); vlc_thread_join( p_input ); vlc_object_release( p_input ); } @@ -777,7 +777,7 @@ static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instanc { input_resource_t *p_resource; - input_StopThread( p_input ); + input_StopThread( p_input, true ); vlc_thread_join( p_input ); p_resource = input_DetachResource( p_input ); @@ -860,7 +860,7 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * return VLC_SUCCESS; } - input_StopThread( p_input ); + input_StopThread( p_input, !p_input->b_eof && !p_input->b_error ); vlc_thread_join( p_input ); p_instance->p_input_resource = input_DetachResource( p_input ); diff --git a/src/playlist/item.c b/src/playlist/item.c index 5e3463c5cd0944271b11c79e860dc1488a398154..a993b79251bb15ed7c31ae55eb7004d89883ea8a 100644 --- a/src/playlist/item.c +++ b/src/playlist/item.c @@ -823,7 +823,7 @@ static void GoAndPreparse( playlist_t *p_playlist, int i_mode, pl_priv(p_playlist)->request.i_skip = 0; pl_priv(p_playlist)->request.p_item = p_toplay; if( pl_priv(p_playlist)->p_input ) - input_StopThread( pl_priv(p_playlist)->p_input ); + input_StopThread( pl_priv(p_playlist)->p_input, true ); pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING; vlc_cond_signal( &pl_priv(p_playlist)->signal ); } diff --git a/src/playlist/thread.c b/src/playlist/thread.c index 0dac88ae5d77a1c1d3ffb070045572c4939c5a77..62e1d74861c2f67b956ae08745761a926a9d7efd 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -473,7 +473,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_StopThread( p_input, true ); } /* This input is dead. Remove it ! */ @@ -514,7 +514,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_StopThread( p_input, false ); } return VLC_SUCCESS; }