[vlc-commits] playlist: remove status.i_status

Rémi Denis-Courmont git at videolan.org
Mon Dec 15 18:25:18 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 15 19:03:59 2014 +0200| [3decf12342f9ac36f2637810f26aaae5196f0d8b] | committer: Rémi Denis-Courmont

playlist: remove status.i_status

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

 src/playlist/control.c           |   29 ++++--------
 src/playlist/engine.c            |    9 +++-
 src/playlist/playlist_internal.h |    1 -
 src/playlist/thread.c            |   95 ++++++++++++++++----------------------
 4 files changed, 57 insertions(+), 77 deletions(-)

diff --git a/src/playlist/control.c b/src/playlist/control.c
index 521c3b6..e3c3e3a 100644
--- a/src/playlist/control.c
+++ b/src/playlist/control.c
@@ -87,39 +87,30 @@ static void playlist_vaControl( playlist_t *p_playlist, int i_query, va_list arg
     }
 
     case PLAYLIST_PLAY:
-        if( pl_priv(p_playlist)->p_input )
-        {
-            pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
-            var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
-            break;
-        }
-        else
+        if( pl_priv(p_playlist)->p_input == NULL )
         {
             pl_priv(p_playlist)->request.b_request = true;
             pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
             pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
             pl_priv(p_playlist)->request.i_skip = 0;
         }
+        else
+            var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
         break;
 
     case PLAYLIST_TOGGLE_PAUSE:
-        if( !pl_priv(p_playlist)->p_input )
-        {   /* FIXME: is this really useful without input? */
-            pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
-            /* return without notifying the playlist thread as there is nothing to do */
-            return;
+        if( pl_priv(p_playlist)->p_input == NULL )
+        {
+            pl_priv(p_playlist)->request.b_request = true;
+            pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
+            pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
+            pl_priv(p_playlist)->request.i_skip = 0;
         }
-
+        else
         if( var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
-        {
-            pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
-        }
         else
-        {
-            pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
-        }
         break;
 
     case PLAYLIST_SKIP:
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 10a6059..edc94dd 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -261,7 +261,6 @@ playlist_t *playlist_Create( vlc_object_t *p_parent )
     pl_priv(p_playlist)->status.p_item = NULL;
     pl_priv(p_playlist)->status.p_node = p_playlist->p_playing;
     pl_priv(p_playlist)->request.b_request = false;
-    pl_priv(p_playlist)->status.i_status = PLAYLIST_STOPPED;
 
     if (ml != NULL)
         playlist_MLLoad( p_playlist );
@@ -496,8 +495,14 @@ playlist_item_t * playlist_CurrentPlayingItem( playlist_t * p_playlist )
 
 int playlist_Status( playlist_t * p_playlist )
 {
+    input_thread_t *p_input = pl_priv(p_playlist)->p_input;
+
     PL_ASSERT_LOCKED;
 
-    return pl_priv(p_playlist)->status.i_status;
+    if( p_input == NULL )
+        return PLAYLIST_STOPPED;
+    if( var_GetInteger( p_input, "state" ) == PAUSE_S )
+        return PLAYLIST_PAUSED;
+    return PLAYLIST_RUNNING;
 }
 
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 558cdfe..20f0343 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -61,7 +61,6 @@ typedef struct playlist_private_t
     struct {
         /* Current status. These fields are readonly, only the playlist
          * main loop can touch it*/
-        playlist_status_t   i_status;  /**< Current status of playlist */
         playlist_item_t *   p_item; /**< Currently playing/active item */
         playlist_item_t *   p_node; /**< Current node to play from */
     } status;
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 357d464..86c1503 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -190,9 +190,8 @@ void ResetCurrentlyPlaying( playlist_t *p_playlist,
  *
  * \param p_playlist the playlist object
  * \param p_item the item to play
- * \return nothing
  */
-static void PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
+static bool PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 {
     playlist_private_t *p_sys = pl_priv(p_playlist);
     input_item_t *p_input = p_item->p_input;
@@ -203,9 +202,6 @@ static void PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 
     p_item->i_nb_played++;
     set_current_status_item( p_playlist, p_item );
-
-    p_sys->status.i_status = PLAYLIST_RUNNING;
-
     assert( p_sys->p_input == NULL );
     PL_UNLOCK;
 
@@ -243,6 +239,7 @@ static void PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 
     PL_LOCK;
     p_sys->p_input = p_input_thread;
+    return p_input_thread != NULL;
 }
 
 /**
@@ -268,7 +265,14 @@ static playlist_item_t *NextItem( playlist_t *p_playlist )
     /* Start the real work */
     if( p_sys->request.b_request )
     {
+        /* Clear the request */
+        p_sys->request.b_request = false;
+
         p_new = p_sys->request.p_item;
+
+        if( p_new == NULL && p_sys->request.p_node == NULL )
+            return NULL; /* Stop request! */
+
         int i_skip = p_sys->request.i_skip;
         PL_DEBUG( "processing request item: %s, node: %s, skip: %i",
                         PLI_NAME( p_sys->request.p_item ),
@@ -351,8 +355,6 @@ static playlist_item_t *NextItem( playlist_t *p_playlist )
             p_new = ARRAY_VAL( p_playlist->current,
                                p_playlist->i_current_index );
         }
-        /* Clear the request */
-        p_sys->request.b_request = false;
     }
     /* "Automatic" item change ( next ) */
     else
@@ -469,41 +471,15 @@ static void LoopInput( playlist_t *p_playlist )
     vlc_cond_wait( &p_sys->signal, &p_sys->lock );
 }
 
-static void LoopRequest( playlist_t *p_playlist, int i_status )
+static bool Next( playlist_t *p_playlist )
 {
-    playlist_private_t *p_sys = pl_priv(p_playlist);
-    assert( !p_sys->p_input );
-
-    /* No input. Several cases
-     *  - No request, running status -> start new item
-     *  - No request, stopped status -> collect garbage
-     *  - Request, running requested -> start new item
-     *  - Request, stopped requested -> collect garbage
-    */
-    if( i_status == PLAYLIST_STOPPED )
-    {
-        p_sys->status.i_status = PLAYLIST_STOPPED;
-        vlc_cond_wait( &p_sys->signal, &p_sys->lock );
-        return;
-    }
-
     playlist_item_t *p_item = NextItem( p_playlist );
-    if( p_item )
-    {
-        msg_Dbg( p_playlist, "starting playback of the new playlist item" );
-        ResyncCurrentIndex( p_playlist, p_item );
-        PlayItem( p_playlist, p_item );
-        return;
-    }
-
-    msg_Dbg( p_playlist, "nothing to play" );
-    p_sys->status.i_status = PLAYLIST_STOPPED;
+    if( p_item == NULL )
+        return false;
 
-    if( var_InheritBool( p_playlist, "play-and-exit" ) )
-    {
-        msg_Info( p_playlist, "end of playlist, exiting" );
-        libvlc_Quit( p_playlist->p_libvlc );
-    }
+    msg_Dbg( p_playlist, "starting playback of new item" );
+    ResyncCurrentIndex( p_playlist, p_item );
+    return PlayItem( p_playlist, p_item );
 }
 
 /**
@@ -515,32 +491,41 @@ static void *Thread ( void *data )
     playlist_private_t *p_sys = pl_priv(p_playlist);
 
     PL_LOCK;
-    for( ;; )
+    while( !p_sys->killed )
     {
-        while( p_sys->p_input != NULL )
-            LoopInput( p_playlist );
+        /* Playlist in stopped state */
+        assert(p_sys->p_input == NULL);
+
+        if( !p_sys->request.b_request )
+        {
+            vlc_cond_wait( &p_sys->signal, &p_sys->lock );
+            continue;
+        }
 
-        if( p_sys->killed )
-            break; /* THE END */
+        while( !p_sys->killed && Next( p_playlist ) )
+        {   /* Playlist in running state */
+            assert(p_sys->p_input != NULL);
 
-        int status = p_sys->status.i_status;
-        if( p_sys->request.b_request )
-            status = (p_sys->request.p_item || p_sys->request.p_node)
-                     ? PLAYLIST_RUNNING : PLAYLIST_STOPPED;
+            do
+                LoopInput( p_playlist );
+            while( p_sys->p_input != NULL );
+        }
 
-        /* Destroy any video display if the playlist is supposed to stop */
-        if( status == PLAYLIST_STOPPED
-         && input_resource_HasVout( p_sys->p_input_resource ) )
+        msg_Dbg( p_playlist, "nothing to play" );
+        if( var_InheritBool( p_playlist, "play-and-exit" ) )
+        {
+            msg_Info( p_playlist, "end of playlist, exiting" );
+            libvlc_Quit( p_playlist->p_libvlc );
+        }
+
+        /* Destroy any video display now (XXX: ugly hack) */
+        if( input_resource_HasVout( p_sys->p_input_resource ) )
         {
             PL_UNLOCK; /* Mind: NO LOCKS while manipulating input resources! */
             input_resource_TerminateVout( p_sys->p_input_resource );
             PL_LOCK;
-            continue; /* lost lock = lost state */
         }
-
-        LoopRequest( p_playlist, status );
     }
-    p_sys->status.i_status = PLAYLIST_STOPPED;
     PL_UNLOCK;
 
     input_resource_Terminate( p_sys->p_input_resource );



More information about the vlc-commits mailing list