[vlc-devel] commit: Simplify a bit main playlist loop. (Laurent Aimar )

git version control git at videolan.org
Mon Jan 5 21:26:43 CET 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Tue Dec 23 09:43:34 2008 +0100| [d2ce7fe9c993e9977d242ae2fe68a1e46975d1ea] | committer: Laurent Aimar 

Simplify a bit main playlist loop.

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

 src/playlist/engine.c            |  117 ++++---------------------------------
 src/playlist/playlist_internal.h |    5 --
 src/playlist/thread.c            |   18 +-----
 3 files changed, 16 insertions(+), 124 deletions(-)

diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 190442a..9735689 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -86,9 +86,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     pl_priv(p_playlist)->i_last_playlist_id = 0;
     pl_priv(p_playlist)->p_input = NULL;
 
-    pl_priv(p_playlist)->gc_date = 0;
-    pl_priv(p_playlist)->b_cant_sleep = false;
-
     ARRAY_INIT( p_playlist->items );
     ARRAY_INIT( p_playlist->all_items );
     ARRAY_INIT( pl_priv(p_playlist)->items_to_delete );
@@ -184,23 +181,6 @@ static void playlist_Destructor( vlc_object_t * p_this )
     msg_Err( p_this, "Destroyed" );
 }
 
-/* Destroy remaining objects */
-static void ObjectGarbageCollector( playlist_t *p_playlist, bool b_force )
-{
-    if( !b_force )
-    {
-        if( mdate() - pl_priv(p_playlist)->gc_date < 1000000 )
-        {
-           pl_priv(p_playlist)->b_cant_sleep = true;
-            return;
-        }
-        else if( pl_priv(p_playlist)->gc_date == 0 )
-            return;
-    }
-
-    pl_priv(p_playlist)->b_cant_sleep = false;
-}
-
 /* Input Callback */
 static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
@@ -214,9 +194,6 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
 
     PL_LOCK;
 
-    if( newval.i_int == INPUT_EVENT_ES )
-        pl_priv(p_playlist)->gc_date = mdate();
-
     vlc_object_signal_unlocked( p_playlist );
 
     PL_UNLOCK;
@@ -331,7 +308,6 @@ void set_current_status_node( playlist_t * p_playlist,
  */
 void playlist_MainLoop( playlist_t *p_playlist )
 {
-    playlist_item_t *p_item = NULL;
     bool b_playexit = var_GetBool( p_playlist, "play-and-exit" );
 
     PL_ASSERT_LOCKED;
@@ -348,23 +324,21 @@ check_input:
     /* If there is an input, check that it doesn't need to die. */
     if( pl_priv(p_playlist)->p_input )
     {
-        if( pl_priv(p_playlist)->request.b_request && !pl_priv(p_playlist)->p_input->b_die )
+        input_thread_t *p_input = pl_priv(p_playlist)->p_input;
+
+        if( pl_priv(p_playlist)->request.b_request && !p_input->b_die )
         {
             PL_DEBUG( "incoming request - stopping current input" );
-            input_StopThread( pl_priv(p_playlist)->p_input );
+            input_StopThread( p_input );
         }
 
         /* This input is dead. Remove it ! */
-        if( pl_priv(p_playlist)->p_input->b_dead )
+        if( p_input->b_dead )
         {
-            int i_activity;
-            input_thread_t *p_input;
             sout_instance_t **pp_sout = &pl_priv(p_playlist)->p_sout;
 
             PL_DEBUG( "dead input" );
 
-            p_input = pl_priv(p_playlist)->p_input;
-
             assert( *pp_sout == NULL );
             if( var_CreateGetBool( p_input, "sout-keep" ) )
                 *pp_sout = input_DetachSout( p_input );
@@ -372,17 +346,13 @@ check_input:
             /* Destroy input */
             playlist_release_current_input( p_playlist );
 
-            pl_priv(p_playlist)->gc_date = mdate();
-            pl_priv(p_playlist)->b_cant_sleep = true;
-
-            i_activity= var_GetInteger( p_playlist, "activity" );
-            var_SetInteger( p_playlist, "activity", i_activity -
-                            DEFAULT_INPUT_ACTIVITY );
-
+            int i_activity= var_GetInteger( p_playlist, "activity" );
+            var_SetInteger( p_playlist, "activity",
+                            i_activity - DEFAULT_INPUT_ACTIVITY );
             goto check_input;
         }
         /* This input is dying, let it do */
-        else if( pl_priv(p_playlist)->p_input->b_die )
+        else if( p_input->b_die )
         {
             PL_DEBUG( "dying input" );
             PL_UNLOCK;
@@ -391,18 +361,13 @@ check_input:
             goto check_input;
         }
         /* This input has finished, ask it to die ! */
-        else if( pl_priv(p_playlist)->p_input->b_error
-                  || pl_priv(p_playlist)->p_input->b_eof )
+        else if( p_input->b_error || p_input->b_eof )
         {
             PL_DEBUG( "finished input" );
-            input_StopThread( pl_priv(p_playlist)->p_input );
+            input_StopThread( p_input );
             /* No need to wait here, we'll wait in the p_input->b_die case */
             goto check_input;
         }
-        else if( pl_priv(p_playlist)->p_input->i_state != INIT_S )
-        {
-            ObjectGarbageCollector( p_playlist, false );
-        }
     }
     else
     {
@@ -417,7 +382,7 @@ check_input:
         if( i_status != PLAYLIST_STOPPED )
         {
             msg_Dbg( p_playlist, "starting new item" );
-            p_item = playlist_NextItem( p_playlist );
+            playlist_item_t *p_item = playlist_NextItem( p_playlist );
 
             if( p_item == NULL )
             {
@@ -429,7 +394,6 @@ check_input:
                     msg_Info( p_playlist, "end of playlist, exiting" );
                     vlc_object_kill( p_playlist->p_libvlc );
                 }
-                ObjectGarbageCollector( p_playlist, true );
                 return;
             }
             playlist_PlayItem( p_playlist, p_item );
@@ -438,64 +402,8 @@ check_input:
         }
         else
         {
-            const bool b_gc_forced = pl_priv(p_playlist)->status.i_status != PLAYLIST_STOPPED;
-
             pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED;
-
-            /* Collect garbage */
-            ObjectGarbageCollector( p_playlist, b_gc_forced );
-        }
-    }
-}
-
-/**
- * Last loop
- *
- * The playlist is dying so do the last loop
- * \param p_playlist the playlist object
- * \return nothing
-*/
-void playlist_LastLoop( playlist_t *p_playlist )
-{
-    /* If there is an input, kill it */
-    while( 1 )
-    {
-        PL_LOCK;
-        if( pl_priv(p_playlist)->p_input == NULL )
-        {
-            PL_UNLOCK;
-            break;
-        }
-
-        if( pl_priv(p_playlist)->p_input->b_dead )
-        {
-            /* remove input */
-            playlist_release_current_input( p_playlist );
-
-            /* sout-keep: no need to anything here.
-             * The last input will destroy its sout, if any, by itself */
-
-            PL_UNLOCK;
-            continue;
-        }
-        else if( pl_priv(p_playlist)->p_input->b_die )
-        {
-            /* This input is dying, leave it alone */
-            ;
-        }
-        else if( pl_priv(p_playlist)->p_input->b_error || pl_priv(p_playlist)->p_input->b_eof )
-        {
-            input_StopThread( pl_priv(p_playlist)->p_input );
-            PL_UNLOCK;
-            continue;
         }
-        else
-        {
-            pl_priv(p_playlist)->p_input->b_eof = 1;
-        }
-        PL_UNLOCK;
-
-        msleep( INTF_IDLE_SLEEP );
     }
 }
 
@@ -540,6 +448,7 @@ static void VariablesInit( playlist_t *p_playlist )
 int playlist_CurrentId( playlist_t * p_playlist )
 {
     return pl_priv(p_playlist)->status.p_item->i_id;
+
 }
 
 bool playlist_IsPlaying( playlist_t * p_playlist )
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index a16f575..c0aac54 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -85,8 +85,6 @@ typedef struct playlist_private_t
     bool     b_tree; /**< Display as a tree */
     bool     b_doing_ml; /**< Doing media library stuff  get quicker */
     bool     b_auto_preparse;
-    bool     b_cant_sleep;
-    mtime_t  gc_date;
     mtime_t  last_rebuild_date;
     bool     b_reset_currently_playing; /** Reset current item array */
     int      i_last_playlist_id; /**< Last id to an item */
@@ -112,9 +110,6 @@ playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist,
 
 /* Engine */
 void playlist_MainLoop( playlist_t * );
-void playlist_LastLoop( playlist_t * );
-void *playlist_PreparseLoop( void * );
-void *playlist_FetcherLoop( void * );
 
 void ResetCurrentlyPlaying( playlist_t *, bool, playlist_item_t * );
 
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 7759189..b588dc9 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -143,26 +143,14 @@ static void* RunControlThread ( vlc_object_t *p_this )
 
         /* The playlist lock has been unlocked, so we can't tell if
          * someone has killed us in the meantime. Check now. */
-        if( !vlc_object_alive( p_playlist ) )
+        if( !vlc_object_alive( p_playlist ) && !pl_priv(p_playlist)->p_input )
             break;
 
-        if( pl_priv(p_playlist)->b_cant_sleep )
-        {
-            /* 100 ms is an acceptable delay for playlist operations */
-            vlc_object_unlock( p_playlist );
-
-            msleep( INTF_IDLE_SLEEP*2 );
-
-            vlc_object_lock( p_playlist );
-        }
-        else
-        {
-            vlc_object_wait( p_playlist );
-        }
+        vlc_object_wait( p_playlist );
     }
     vlc_object_unlock( p_playlist );
 
-    playlist_LastLoop( p_playlist );
     vlc_restorecancel (canc);
     return NULL;
 }
+




More information about the vlc-devel mailing list