From: Laurent Aimar Date: Mon, 9 Mar 2009 19:38:46 +0000 (+0100) Subject: Added a INPUT_EVENT_ABORT event to detect user requested abort. X-Git-Tag: 1.0.0-pre1~172 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=8236d4c98f0e531a3be614b8dff14d1a60e05eec;p=vlc Added a INPUT_EVENT_ABORT event to detect user requested abort. --- diff --git a/include/vlc_input.h b/include/vlc_input.h index a119c023e8..4bac4d5a4a 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 e716731b1e..6d12d8a896 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 b2ee096201..cdc85e66aa 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 ddef8fd081..242bf1fd01 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 1116c5c116..b6ed2bfc60 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 bdf91af2bc..b504da71c3 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 d611eb86a6..23e6004346 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 5e3463c5cd..a993b79251 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 0dac88ae5d..62e1d74861 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; }