]> git.sesse.net Git - vlc/blobdiff - src/playlist/playlist.c
* src/playlist/item-ext.c: playlist_AddExt() needs to duplicate the input options...
[vlc] / src / playlist / playlist.c
index 1209e9647543f81ed130410af82ac89b1465bec0..1e5d2f2c38ee163a8b44f800230591e27368a156 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.c : Playlist management functions
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: playlist.c,v 1.72 2004/01/06 08:50:20 zorglub Exp $
+ * $Id: playlist.c,v 1.82 2004/02/23 21:57:56 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -35,7 +35,6 @@
 #include "vlc_playlist.h"
 
 #define PLAYLIST_FILE_HEADER_0_5  "# vlc playlist file version 0.5"
-#define PLAYLIST_FILE_HEADER_0_6  "# vlc playlist file version 0.6"
 
 /*****************************************************************************
  * Local prototypes
@@ -101,8 +100,10 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
     p_playlist->pp_groups = NULL;
     p_playlist->i_last_group = 0;
     p_playlist->i_last_id = 0;
+    p_playlist->i_sort = SORT_ID;
+    p_playlist->i_order = ORDER_NORMAL;
 
-    playlist_CreateGroup( p_playlist, "Normal" );
+    playlist_CreateGroup( p_playlist, _("Normal") );
 
     if( vlc_thread_create( p_playlist, "playlist", RunThread,
                            VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
@@ -161,7 +162,7 @@ void playlist_Destroy( playlist_t * p_playlist )
  * \param i_command the command to do
  * \param i_arg the argument to the command. See playlist_command_t for details
  */
- void playlist_Command( playlist_t * p_playlist, playlist_command_t i_command,
+void playlist_Command( playlist_t * p_playlist, playlist_command_t i_command,
                        int i_arg )
 {
     vlc_value_t val;
@@ -261,36 +262,31 @@ void playlist_Destroy( playlist_t * p_playlist )
 }
 
 
-static void ObjectGarbageCollector( playlist_t *p_playlist,
-                                    int i_type,
-                                    mtime_t *pi_obj_destroyed_date )
+static mtime_t ObjectGarbageCollector( playlist_t *p_playlist, int i_type,
+                                       mtime_t destroy_date )
 {
     vlc_object_t *p_obj;
-    if( *pi_obj_destroyed_date > mdate() )
-    {
-        return;
-    }
 
-    if( *pi_obj_destroyed_date == 0 )
+    if( destroy_date > mdate() ) return destroy_date;
+
+    if( destroy_date == 0 )
     {
         /* give a little time */
-        *pi_obj_destroyed_date = mdate() + I64C(300000);
+        return mdate() + I64C(1000000);
     }
     else
     {
-        while( ( p_obj = vlc_object_find( p_playlist,
-                                           i_type,
-                                           FIND_CHILD ) ) )
+        while( ( p_obj = vlc_object_find( p_playlist, i_type, FIND_CHILD ) ) )
         {
             if( p_obj->p_parent != (vlc_object_t*)p_playlist )
             {
-                /* only first chiled (ie unused) */
+                /* only first child (ie unused) */
                 vlc_object_release( p_obj );
                 break;
             }
             if( i_type == VLC_OBJECT_VOUT )
             {
-                msg_Dbg( p_playlist, "vout garbage collector destroying 1 vout" );
+                msg_Dbg( p_playlist, "garbage collector destroying 1 vout" );
                 vlc_object_detach( p_obj );
                 vlc_object_release( p_obj );
                 vout_Destroy( (vout_thread_t *)p_obj );
@@ -301,7 +297,7 @@ static void ObjectGarbageCollector( playlist_t *p_playlist,
                 sout_DeleteInstance( (sout_instance_t*)p_obj );
             }
         }
-        *pi_obj_destroyed_date = 0;
+        return 0;
     }
 }
 
@@ -376,22 +372,17 @@ static void RunThread ( playlist_t *p_playlist )
                     input_StopThread( p_playlist->p_input );
                     vlc_mutex_unlock( &p_playlist->object_lock );
                 }
-
-                val.i_int = p_playlist->i_index;
-                var_Set( p_playlist, "playlist-current", val);
-#if 0
-                val.b_bool = VLC_TRUE;
-                var_Set( p_playlist, "intf-change", val );
-#endif
                 continue;
             }
             else if( p_playlist->p_input->stream.control.i_status != INIT_S )
             {
                 vlc_mutex_unlock( &p_playlist->object_lock );
-                ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT,
-                                        &i_vout_destroyed_date );
-                ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT,
-                                        &i_sout_destroyed_date );
+                i_vout_destroyed_date =
+                    ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT,
+                                            i_vout_destroyed_date );
+                i_sout_destroyed_date =
+                    ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT,
+                                            i_sout_destroyed_date );
                 vlc_mutex_lock( &p_playlist->object_lock );
             }
         }
@@ -409,10 +400,10 @@ static void RunThread ( playlist_t *p_playlist )
         else if( p_playlist->i_status == PLAYLIST_STOPPED )
         {
             vlc_mutex_unlock( &p_playlist->object_lock );
-            ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT,
-                                    &i_sout_destroyed_date );
-            ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT,
-                                    &i_vout_destroyed_date );
+            i_sout_destroyed_date =
+                ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, mdate() );
+            i_vout_destroyed_date =
+                ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, mdate() );
             vlc_mutex_lock( &p_playlist->object_lock );
         }
         vlc_mutex_unlock( &p_playlist->object_lock );
@@ -537,9 +528,7 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
     /* Boundary check */
     if( p_playlist->i_index >= p_playlist->i_size )
     {
-        if( p_playlist->i_status == PLAYLIST_STOPPED
-             || b_random
-             || b_loop )
+        if( p_playlist->i_status == PLAYLIST_STOPPED || b_random || b_loop )
         {
             p_playlist->i_index -= p_playlist->i_size
                          * ( p_playlist->i_index / p_playlist->i_size );
@@ -557,8 +546,8 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
     }
 
     /* Check that the item is enabled */
-   if( p_playlist->pp_items[p_playlist->i_index]->b_enabled == VLC_FALSE &&
-       p_playlist->i_enabled != 0)
+    if( p_playlist->pp_items[p_playlist->i_index]->b_enabled == VLC_FALSE &&
+        p_playlist->i_enabled != 0)
     {
         SkipItem( p_playlist , 1 );
     }
@@ -572,6 +561,8 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
  *****************************************************************************/
 static void PlayItem( playlist_t *p_playlist )
 {
+    playlist_item_t *p_item;
+    int             i, j;
     vlc_value_t val;
     if( p_playlist->i_index == -1 )
     {
@@ -579,19 +570,22 @@ static void PlayItem( playlist_t *p_playlist )
         {
             return;
         }
-
         SkipItem( p_playlist, 1 );
     }
-
     if( p_playlist->i_enabled == 0)
     {
         return;
     }
 
     msg_Dbg( p_playlist, "creating new input thread" );
-    p_playlist->p_input = input_CreateThread( p_playlist,
-                                  p_playlist->pp_items[p_playlist->i_index] );
+    p_item = p_playlist->pp_items[p_playlist->i_index];
+
+    p_item->i_nb_played++;
+
+    p_playlist->p_input = input_CreateThread( p_playlist, p_item->psz_uri,
+                                              p_item->ppsz_options,
+                                              p_item->i_options );
 
     val.i_int = p_playlist->i_index;
-    var_Set( p_playlist, "item-change", val );
+    var_Set( p_playlist, "playlist-current", val);
 }