[vlc-devel] commit: Added a INPUT_EVENT_ABORT event to detect user requested abort. ( Laurent Aimar )
git version control
git at videolan.org
Mon Mar 9 20:49:10 CET 2009
vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Mon Mar 9 20:38:46 2009 +0100| [8236d4c98f0e531a3be614b8dff14d1a60e05eec] | committer: Laurent Aimar
Added a INPUT_EVENT_ABORT event to detect user requested abort.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8236d4c98f0e531a3be614b8dff14d1a60e05eec
---
include/vlc_input.h | 18 +++++++++++++++---
modules/services_discovery/podcast.c | 4 ++--
src/control/media_player.c | 17 +++++++++++------
src/input/event.c | 4 ++++
src/input/event.h | 1 +
src/input/input.c | 4 +++-
src/input/vlm.c | 6 +++---
src/playlist/item.c | 2 +-
src/playlist/thread.c | 4 ++--
9 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/include/vlc_input.h b/include/vlc_input.h
index a119c02..4bac4d5 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 e716731..6d12d8a 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 b2ee096..cdc85e6 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 ddef8fd..242bf1f 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 1116c5c..b6ed2bf 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 bdf91af..b504da7 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 d611eb8..23e6004 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 5e3463c..a993b79 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 0dac88a..62e1d74 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;
}
More information about the vlc-devel
mailing list