[vlc-devel] commit: Stop timeshifting when unused. (Laurent Aimar )

git version control git at videolan.org
Mon Nov 17 20:16:40 CET 2008


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun Nov 16 02:55:38 2008 +0100| [ae7defefe8c13191a2ab77925a88dcee0195c35e] | committer: Laurent Aimar 

Stop timeshifting when unused.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ae7defefe8c13191a2ab77925a88dcee0195c35e
---

 src/input/es_out_timeshift.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index a67593f..40d24d2 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -174,10 +174,13 @@ static int          Control( es_out_t *, int i_query, va_list );
 static void         Destroy( es_out_t * );
 
 static int          TsStart( es_out_t * );
+static void         TsAutoStop( es_out_t * );
+
 static void         TsStop( ts_thread_t * );
 static void         TsPushCmd( ts_thread_t *, const ts_cmd_t * );
 static int          TsPopCmdLocked( ts_thread_t *, ts_cmd_t * );
 static bool         TsHasCmd( ts_thread_t * );
+static bool         TsIsUnused( ts_thread_t * );
 static int          TsChangePause( ts_thread_t *, bool b_source_paused, bool b_paused, mtime_t i_date );
 static int          TsChangeRate( ts_thread_t *, int i_src_rate, int i_rate );
 
@@ -290,6 +293,8 @@ static es_out_id_t *Add( es_out_t *p_out, const es_format_t *p_fmt )
 
     vlc_mutex_lock( &p_sys->lock );
 
+    TsAutoStop( p_out );
+
     if( CmdInitAdd( &cmd, p_es, p_fmt, p_sys->b_delayed ) )
     {
         vlc_mutex_unlock( &p_sys->lock );
@@ -316,6 +321,8 @@ static int Send( es_out_t *p_out, es_out_id_t *p_es, block_t *p_block )
 
     vlc_mutex_lock( &p_sys->lock );
 
+    TsAutoStop( p_out );
+
     CmdInitSend( &cmd, p_es, p_block );
     if( p_sys->b_delayed )
         TsPushCmd( p_sys->p_thread, &cmd );
@@ -333,6 +340,8 @@ static void Del( es_out_t *p_out, es_out_id_t *p_es )
 
     vlc_mutex_lock( &p_sys->lock );
 
+    TsAutoStop( p_out );
+
     CmdInitDel( &cmd, p_es );
     if( p_sys->b_delayed )
         TsPushCmd( p_sys->p_thread, &cmd );
@@ -581,7 +590,11 @@ static int Control( es_out_t *p_out, int i_query, va_list args )
     int i_ret;
 
     vlc_mutex_lock( &p_sys->lock );
+
+    TsAutoStop( p_out );
+
     i_ret = ControlLocked( p_out, i_query, args );
+
     vlc_mutex_unlock( &p_sys->lock );
 
     return i_ret;
@@ -638,6 +651,18 @@ static int TsStart( es_out_t *p_out )
 
     return VLC_SUCCESS;
 }
+static void TsAutoStop( es_out_t *p_out )
+{
+    es_out_sys_t *p_sys = p_out->p_sys;
+
+    if( !p_sys->b_delayed || !TsIsUnused( p_sys->p_thread ) )
+        return;
+
+    msg_Warn( p_sys->p_input, "es out timeshift: auto stop" );
+    TsStop( p_sys->p_thread );
+
+    p_sys->b_delayed = false;
+}
 static void TsStop( ts_thread_t *p_ts )
 {
     vlc_object_kill( p_ts );
@@ -697,6 +722,18 @@ static bool TsHasCmd( ts_thread_t *p_ts )
 
     return b_cmd;
 }
+static bool TsIsUnused( ts_thread_t *p_ts )
+{
+    bool b_unused;
+
+    vlc_mutex_lock( &p_ts->lock );
+    b_unused = !p_ts->b_paused &&
+               p_ts->i_rate == p_ts->i_rate_source &&
+               p_ts->i_cmd <= 0;
+    vlc_mutex_unlock( &p_ts->lock );
+
+    return b_unused;
+}
 static int TsChangePause( ts_thread_t *p_ts, bool b_source_paused, bool b_paused, mtime_t i_date )
 {
     vlc_mutex_lock( &p_ts->lock );




More information about the vlc-devel mailing list