]> git.sesse.net Git - vlc/commitdiff
Rebuild the array of currently playing items as a background task.
authorClément Stenac <zorglub@videolan.org>
Sat, 21 Oct 2006 16:59:09 +0000 (16:59 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 21 Oct 2006 16:59:09 +0000 (16:59 +0000)
This array is now usable as a reliable source of data for size
Use playlist_CurrentSize(p_playlist) to retrieve the size of the current playset.

15 files changed:
include/vlc_messages.h
include/vlc_playlist.h
modules/control/hotkeys.c
modules/gui/beos/InterfaceWindow.cpp
modules/gui/beos/ListViews.cpp
modules/gui/macosx/playlist.m
modules/gui/wxwidgets/dialogs/playlist.cpp
modules/gui/wxwidgets/dialogs/wizard.cpp
modules/gui/wxwidgets/menus.cpp
src/playlist/control.c
src/playlist/engine.c
src/playlist/item.c
src/playlist/playlist_internal.h
src/playlist/search.c
src/playlist/thread.c

index 00f4c1dcd59eca7deac95b58e378d8b703744b14..5a8f659dc15374ae335c7ffdf7f52fc0ec253d18 100644 (file)
@@ -259,7 +259,7 @@ enum
     STATS_DISPLAYED_PICTURES,
     STATS_LOST_PICTURES,
 
-    STATS_TIMER_PLAYLIST_WALK,
+    STATS_TIMER_PLAYLIST_BUILD,
     STATS_TIMER_ML_LOAD,
     STATS_TIMER_ML_DUMP,
     STATS_TIMER_INTERACTION,
index 9acba2652daafe214723738cb4d5cb92bb1f1ad9..a8a98aa7b25aefe57d35d29ef581360b2720969c 100644 (file)
@@ -111,6 +111,7 @@ struct playlist_t
     int                   i_current_index; /**< Index in current array */
     /** Reset current item ? */
     vlc_bool_t            b_reset_currently_playing;
+    mtime_t               last_rebuild_date;
 
     int                   i_last_playlist_id; /**< Last id to an item */
     int                   i_last_input_id ; /**< Last id on an input */
@@ -433,6 +434,12 @@ static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist )
     return( b_empty );
 }
 
+/** Tell the number of items in the current playing context */
+static inline int playlist_CurrentSize( vlc_object_t *p_this )
+{
+    return p_this->p_libvlc->p_playlist->current.i_size;
+}
+
 /** Ask the playlist to do some work */
 static inline void playlist_Signal( playlist_t *p_playlist )
 {
index 8fbe4cd689d42bb16cf76a4fdd6d3db74a32e570..00134cfb24afcdf2638558574671590690a95201 100644 (file)
@@ -796,16 +796,14 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num )
     var_Get( p_intf, psz_bookmark_name, &val );
 
     char *psz_bookmark = strdup( val.psz_string );
-    for( i = 0; i < p_playlist->items.i_size; i++)
-    {
-        if( !strcmp( psz_bookmark,
-                     ARRAY_VAL( p_playlist->items,i )->p_input->psz_uri ) )
+    PL_LOCK;
+    FOREACH_ARRAY( playlist_item_t *p_item, p_playlist->items )
+        if( !strcmp( psz_bookmark, p_item->p_input->psz_uri ) )
         {
-            playlist_LockControl( p_playlist, PLAYLIST_VIEWPLAY, NULL,
-                                  ARRAY_VAL( p_playlist->items, i ) );
+            playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, NULL, p_item );
             break;
         }
-    }
+    FOREACH_END();
     vlc_object_release( p_playlist );
 }
 
index b883bfb486e013cc8c293619c5fd9c8277510b5f..affd8016471d47a9093124daa889c9f89c44b8af 100644 (file)
@@ -842,7 +842,7 @@ void InterfaceWindow::UpdateInterface()
             b_playlist_update = false;
         }
 #endif
-        p_mediaControl->SetEnabled( p_playlist->i_size );
+        p_mediaControl->SetEnabled( !playlist_IsEmpty( p_playlist ) );
     }
 
     if( p_input )
index 7b515cb3ff5d178edc920250fd7ed954cfd4a7d0..74f677c9fb54c02a9d767de6a17929ff3a243f7c 100644 (file)
@@ -988,26 +988,20 @@ PlaylistView::SetPlaying( bool playing )
 void
 PlaylistView::RebuildList()
 {
-    playlist_t * p_playlist;
-    p_playlist = (playlist_t *) vlc_object_find( p_intf,
-        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-
-    if( !p_playlist )
-    {
-        return;
-    }
+    playlist_t * p_playlist = pl_Yield( p_intf );
 
     // remove all items
     BListItem * item;
     int32 count = CountItems();
     while( ( item = RemoveItem( --count ) ) )
         delete item;
-    
+
     // rebuild listview from VLC's playlist
-    vlc_mutex_lock( &p_playlist->object_lock );
-    for( int i = 0; i < p_playlist->i_size; i++ )
-        AddItem( new PlaylistItem( p_playlist->pp_items[i]->input.psz_name ) );
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    PL_LOCK;
+    FOREACH_ARRAY( playlist_item_t *p_item, p_playlist->items )
+        AddItem( new PlaylistItem( p_item->p_input->psz_name ) );
+    FOREACH_END();
+    PL_UNLOCK;
 
     vlc_object_release( p_playlist );
 }
index c3aba6cb691781a84a9f775c6ac8e462d43ba30f..5d79a030dd813f19c7f6ac337a679804fc1eb3f8 100644 (file)
@@ -464,11 +464,11 @@ NSLog( @"expandable" );
 
     playlist_t *p_playlist = pl_Yield( VLCIntf );
 
-    /** \todo fix i_size use */
-    if( p_playlist->items.i_size >= 2 )
+    if( playlist_CurrentSize( p_playlist ) >= 2 )
     {
         [o_status_field setStringValue: [NSString stringWithFormat:
-                    _NS("%i items in the playlist"), p_playlist->items.i_size]];
+                    _NS("%i items in the playlist"),
+                               playlist_CurrentSize( p_playlist )]];
     }
     else
     {
@@ -1365,13 +1365,11 @@ NSLog( @"expandable" );
     id o_value = [super outlineView: outlineView child: index ofItem: item];
     playlist_t *p_playlist = pl_Yield( VLCIntf );
 
-    /* FIXME: playlist->i_size doesn't provide the correct number of items anymore
-     * check the playlist API for the fixed function, once zorglub implemented it -- fpk, 9/17/06 */
-    /** \todo fix i_size use */
-    if( p_playlist->items.i_size >= 2 )
+    if( playlist_CurrentSize( p_playlist )  >= 2 )
     {
         [o_status_field setStringValue: [NSString stringWithFormat:
-                    _NS("%i items in the playlist"), p_playlist->items.i_size]];
+                    _NS("%i items in the playlist"),
+                       playlist_CurrentSize( p_playlist )]];
     }
     else
     {
index 030fc1270558f9f7875c73b824f9c53dcf463991..e9e33750913671a1244747dc057b2136a737c2ff 100644 (file)
@@ -938,7 +938,7 @@ void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
 
     wxString filter = wxT("");
 
-    if( p_playlist->i_size == 0 )
+    if( playlist_IsEmpty( p_playlist ) )
     {
         wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
                       wxICON_WARNING | wxOK, this );
index 4181b4d690ddf652ab9cccc1907ba7ffb3efa23d..6cf4dd3ad3dbf66a87bae6d471946ce52cc73a13 100644 (file)
@@ -582,7 +582,7 @@ wizInputPage::wizInputPage( wxWizard *parent, wxWizardPage *prev, intf_thread_t
 
     if( p_playlist )
     {
-        if( p_playlist->i_size > 0)
+        if( !playlist_IsEmpty( p_playlist ) )
         {
             listview = new wxListView( this, ListView_Event,
                                        wxDefaultPosition, wxDefaultSize,
@@ -591,19 +591,6 @@ wizInputPage::wizInputPage( wxWizard *parent, wxWizardPage *prev, intf_thread_t
             listview->InsertColumn( 1, wxU(_("URI")) );
             listview->SetColumnWidth( 0, 250 );
             listview->SetColumnWidth( 1, 100 );
-#if 0
-            for( int i=0 ; i < p_playlist->i_size ; i++ )
-            {
-                wxString filename = wxL2U( p_playlist->pp_items[i]->input.
-                                                                    psz_name );
-                listview->InsertItem( i, filename );
-                listview->SetItem( i, 1, wxL2U( p_playlist->pp_items[i]->
-                                                            input.psz_uri) );
-                listview->SetItemData( i,
-                                  (long)p_playlist->pp_items[i]->input.i_id );
-            }
-            listview->Select( p_playlist->i_index , TRUE);
-#endif
             mainSizer->Add( listview, 1, wxALL|wxEXPAND, 5 );
 
             listview->Hide();
index cb8b6227de787e8f29d08428c4e85bf2d9050aaa..7a7fa79c9a8c64bf6e80b76933a19ede3e3791d9 100644 (file)
@@ -271,7 +271,7 @@ int IntfAutoMenuBuilder( intf_thread_t *p_intf, ArrayOfInts &ri_objects,
     } \
     else \
     { \
-        if( p_playlist && p_playlist->i_size ) \
+        if( p_playlist && !playlist_IsEmpty( p_playlist->i_size ) ) \
         { \
             popupmenu.InsertSeparator( 0 ); \
             popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
index 735f58db1fbb284cbbc852eeca0e36e8aae6d1e9..f6703e0297fe89eff3be2f108209e3213effa3f3 100644 (file)
@@ -278,10 +278,12 @@ static void ResyncCurrentIndex(playlist_t *p_playlist, playlist_item_t *p_cur )
      PL_DEBUG("%s is at %i", PLI_NAME(p_cur), p_playlist->i_current_index );
 }
 
-static void ResetCurrentlyPlaying( playlist_t *p_playlist, vlc_bool_t b_random,
-                                   playlist_item_t *p_cur )
+void ResetCurrentlyPlaying( playlist_t *p_playlist, vlc_bool_t b_random,
+                            playlist_item_t *p_cur )
 {
     playlist_item_t *p_next = NULL;
+    stats_TimerStart( p_playlist, "Items array build",
+                      STATS_TIMER_PLAYLIST_BUILD );
     PL_DEBUG("rebuilding array of current - root %s",
               PLI_NAME(p_playlist->status.p_node) );
     ARRAY_RESET(p_playlist->current);
@@ -319,6 +321,7 @@ static void ResetCurrentlyPlaying( playlist_t *p_playlist, vlc_bool_t b_random,
         }
     }
     p_playlist->b_reset_currently_playing = VLC_FALSE;
+    stats_TimerStop( p_playlist, STATS_TIMER_PLAYLIST_BUILD );
 }
 
 /** This function calculates the next playlist item, depending
@@ -389,6 +392,7 @@ playlist_item_t * playlist_NextItem( playlist_t *p_playlist )
             i_skip++;
 
         if( p_playlist->b_reset_currently_playing )
+            /* A bit too bad to reset twice ... */
             ResetCurrentlyPlaying( p_playlist, b_random, p_new );
         else if( p_new )
             ResyncCurrentIndex( p_playlist, p_new );
index adc16160f51c768e654ad5d8c09e51a364fe432c..86a3c146233c9dce3ab907fe073210b59849a4d8 100644 (file)
@@ -38,6 +38,7 @@ static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
                            vlc_value_t oldval, vlc_value_t newval, void *a )
 {
     ((playlist_t*)p_this)->b_reset_currently_playing = VLC_TRUE;
+    playlist_Signal( ((playlist_t*)p_this) );
     return VLC_SUCCESS;
 }
 
@@ -80,6 +81,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
 
     p_playlist->i_current_index = 0;
     p_playlist->b_reset_currently_playing = VLC_TRUE;
+    p_playlist->last_rebuild_date = 0;
 
     i_tree = var_CreateGetBool( p_playlist, "playlist-tree" );
     p_playlist->b_always_tree = (i_tree == 1);
@@ -244,20 +246,24 @@ void playlist_MainLoop( playlist_t *p_playlist )
     vlc_bool_t b_playexit = var_GetBool( p_playlist, "play-and-exit" );
     PL_LOCK;
 
-    /* First, check if we have something to do */
-    if( p_playlist->request.b_request )
+    if( p_playlist->b_reset_currently_playing &&
+        mdate() - p_playlist->last_rebuild_date > 30000 ) // 30 ms
     {
-        /* Stop the existing input */
-        if( p_playlist->p_input && !p_playlist->p_input->b_die )
-        {
-            PL_DEBUG( "incoming request - stopping current input" );
-            input_StopThread( p_playlist->p_input );
-        }
+        ResetCurrentlyPlaying( p_playlist, var_GetBool( p_playlist, "random"),
+                             p_playlist->status.p_item );
+        p_playlist->last_rebuild_date = mdate();
     }
+
 check_input:
     /* If there is an input, check that it doesn't need to die. */
     if( p_playlist->p_input )
     {
+        if( p_playlist->request.b_request && !p_playlist->p_input->b_die )
+        {
+            PL_DEBUG( "incoming request - stopping current input" );
+            input_StopThread( p_playlist->p_input );
+        }
+
         /* This input is dead. Remove it ! */
         if( p_playlist->p_input->b_dead )
         {
@@ -340,10 +346,7 @@ check_input:
                 p_playlist->request.i_status != PLAYLIST_STOPPED ) )
          {
              msg_Dbg( p_playlist, "starting new item" );
-             stats_TimerStart( p_playlist, "Playlist walk",
-                                  STATS_TIMER_PLAYLIST_WALK );
              p_item = playlist_NextItem( p_playlist );
-             stats_TimerStop( p_playlist, STATS_TIMER_PLAYLIST_WALK );
 
              if( p_item == NULL )
              {
index 3a610f72bd7eac195aa5e025a9200419808e67e7..eefdf86a45355958bb8192c02a534fdee0a37ba3 100644 (file)
@@ -404,6 +404,7 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
                                       p_playlist->p_root_onelevel, VLC_FALSE );
         }
         p_playlist->b_reset_currently_playing = VLC_TRUE;
+        vlc_cond_signal( &p_playlist->object_wait );
         var_SetInteger( p_playlist, "item-change", p_item_in_category->
                                                         p_input->i_id );
         return p_item_in_category;
@@ -492,6 +493,7 @@ static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item,
 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
                        playlist_item_t *p_node, int i_newpos )
 {
+    int i_ret;
     /* Drop on a top level node. Move in the two trees */
     if( p_node->p_parent == p_playlist->p_root_category ||
         p_node->p_parent == p_playlist->p_root_onelevel )
@@ -529,10 +531,13 @@ int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
             if( p_node_category && p_item_category )
                 TreeMove( p_playlist, p_item_category, p_node_category, 0 );
         }
-        return VLC_SUCCESS;
+        i_ret = VLC_SUCCESS;
     }
     else
-        return TreeMove( p_playlist, p_item, p_node, i_newpos );
+        i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos );
+    p_playlist->b_reset_currently_playing = VLC_TRUE;
+    vlc_cond_signal( &p_playlist->object_wait );
+    return i_ret;
 }
 
 /** Send a notification that an item has been added to a node */
@@ -545,6 +550,7 @@ void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
     p_add->i_node = i_node_id;
     val.p_address = p_add;
     p_playlist->b_reset_currently_playing = VLC_TRUE;
+    vlc_cond_signal( &p_playlist->object_wait );
     var_Set( p_playlist, "item-append", val );
     free( p_add );
 }
index 63a664e11c05f2a16b90e63a5ad6dd980835e1cf..b77a2bf99c69092e05a2160691e2b2ec55091cf4 100644 (file)
@@ -67,6 +67,8 @@ void playlist_LastLoop( playlist_t * );
 void playlist_PreparseLoop( playlist_preparse_t * );
 void playlist_SecondaryPreparseLoop( playlist_secondary_preparse_t * );
 
+void ResetCurrentlyPlaying( playlist_t *, vlc_bool_t, playlist_item_t * );
+
 /* Control */
 playlist_item_t * playlist_NextItem  ( playlist_t * );
 int playlist_PlayItem  ( playlist_t *, playlist_item_t * );
@@ -98,7 +100,8 @@ playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist,
  * @}
  */
 
-#define PLAYLIST_DEBUG 1
+//#define PLAYLIST_DEBUG 1
+#undef PLAYLIST_DEBUG
 
 #ifdef PLAYLIST_DEBUG
 #define PL_DEBUG( msg, args... ) msg_Dbg( p_playlist, msg, ## args )
index 00077f44e9bba42f2717ca9a4d6a0b84587a0d2d..ba7a52c6818a9fe332c150ded7e8e0220bdecc6e 100644 (file)
@@ -95,5 +95,6 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
         else
             p_item->i_flags |= PLAYLIST_DBL_FLAG;
    }
+   vlc_cond_signal( &p_playlist->object_wait );
    return VLC_SUCCESS;
 }
index 65759bfcf69fa1cd24bf2188c7d6f10934ff6f42..0c08a8bc0c20cfa38b97d1db039d6a9d1e4764cc 100644 (file)
@@ -36,11 +36,9 @@ static void RunPreparse( playlist_preparse_t * );
 static void RunSecondaryPreparse( playlist_secondary_preparse_t * );
 
 static playlist_t * CreatePlaylist( vlc_object_t *p_parent );
-static void HandlePlaylist( playlist_t * );
 static void EndPlaylist( playlist_t * );
 static void DestroyPlaylist( playlist_t * );
 
-static void HandleInteraction( playlist_t * );
 static void DestroyInteraction( playlist_t * );
 
 /*****************************************************************************
@@ -174,8 +172,10 @@ static void RunControlThread ( playlist_t *p_playlist )
     {
         i_loops++;
 
-        HandleInteraction( p_playlist );
-        HandlePlaylist( p_playlist );
+        if( p_playlist->p_interaction )
+            intf_InteractionManage( p_playlist );
+
+        playlist_MainLoop( p_playlist );
         if( p_playlist->b_cant_sleep )
         {
             /* 100 ms is an acceptable delay for playlist operations */
@@ -206,11 +206,6 @@ static void DestroyPlaylist( playlist_t *p_playlist )
     playlist_Destroy( p_playlist );
 }
 
-static void HandlePlaylist( playlist_t *p_playlist )
-{
-    playlist_MainLoop( p_playlist );
-}
-
 static void EndPlaylist( playlist_t *p_playlist )
 {
     playlist_LastLoop( p_playlist );
@@ -245,14 +240,3 @@ static void DestroyInteraction( playlist_t *p_playlist )
         p_playlist->p_interaction = NULL;
     }
 }
-
-static void HandleInteraction( playlist_t *p_playlist )
-{
-    if( p_playlist->p_interaction )
-    {
-        stats_TimerStart( p_playlist, "Interaction thread",
-                          STATS_TIMER_INTERACTION );
-        intf_InteractionManage( p_playlist );
-        stats_TimerStop( p_playlist, STATS_TIMER_INTERACTION );
-    }
-}