[vlc-devel] commit: Pass pointer rather than ID for playlist item-current ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat May 16 19:27:53 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May 16 20:10:06 2009 +0300| [6bbc4b9934ba00f6495672a660927e91e904e1b9] | committer: Rémi Denis-Courmont 

Pass pointer rather than ID for playlist item-current

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

 modules/gui/qt4/input_manager.cpp  |   23 ++++++++++++++++-------
 modules/gui/skins2/src/vlcproc.cpp |    6 +++++-
 modules/misc/lua/libs/playlist.c   |   14 +++++++++++++-
 modules/misc/notify/telepathy.c    |    4 ++--
 src/playlist/engine.c              |    3 +--
 src/playlist/thread.c              |    2 +-
 6 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index c89f5b9..e26acf1 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -255,8 +255,9 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
     InputManager *im = (InputManager*)param;
+    input_item_t *p_item = static_cast<input_item_t *>(newval.p_address);
 
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    IMEvent *event = new IMEvent( ItemChanged_Type, p_item->i_id );
     QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
@@ -884,10 +885,18 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
              im, setInput( input_thread_t * ) );
 
     /* emit check if playlist has already started playing */
-    IMEvent *event = new IMEvent( ItemChanged_Type,
-                                  var_GetInteger( THEPL, "item-current" ) );
-    customEvent( event );
-    delete event;
+    input_thread_t *p_input = playlist_CurrentInput( THEPL );
+    if( p_input )
+    {
+        input_item_t *p_item = input_GetItem( p_input );
+        if( p_item )
+        {
+            IMEvent *event = new IMEvent( ItemChanged_Type, p_item->i_id );
+            customEvent( event );
+            delete event;
+        }
+        vlc_object_release( p_input );
+    }
 }
 
 MainInputManager::~MainInputManager()
@@ -1003,11 +1012,11 @@ void MainInputManager::activatePlayQuit( bool b_exit )
 
 /* Static callbacks for MIM */
 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
-                        vlc_value_t oldval, vlc_value_t newval, void *param )
+                        vlc_value_t oldval, vlc_value_t, void *param )
 {
     MainInputManager *mim = (MainInputManager*)param;
 
-    IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
+    IMEvent *event = new IMEvent( ItemChanged_Type, 0 );
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index 8558f39..806bee7 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -479,6 +479,7 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
                                void *pParam )
 {
     VlcProc *pThis = (VlcProc*)pParam;
+    input_item_t *p_item = newval.p_address;
 
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
 
@@ -486,10 +487,13 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
     pThis->updateStreamName();
 
     // Create two playtree notify commands: one for old item, one for new
+#if 0 /* FIXME: Heck, no! You cannot do that.
+         There is no warranty that the old item is still valid. */
     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
                                                          oldVal.i_int );
     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
-    pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), newVal.i_int );
+#endif
+    pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), p_item->i_id );
     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
 
     return VLC_SUCCESS;
diff --git a/modules/misc/lua/libs/playlist.c b/modules/misc/lua/libs/playlist.c
index 58ce8c0..9e839a7 100644
--- a/modules/misc/lua/libs/playlist.c
+++ b/modules/misc/lua/libs/playlist.c
@@ -318,7 +318,19 @@ static int vlclua_playlist_search( lua_State *L )
 static int vlclua_playlist_current( lua_State *L )
 {
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    lua_pushinteger( L, var_GetInteger( p_playlist, "item-current" ) );
+    input_thread_t *p_input = playlist_CurrentInput( p_playlist );
+    int id = -1;
+
+    if( p_input )
+    {
+        input_item_t *p_item = input_GetItem( p_input );
+        if( p_item )
+            id = p_item->i_id;
+        vlc_object_release( p_input );
+    }
+
+#warning Indexing input items by ID is unsafe,
+    lua_pushinteger( L, id );
     vlclua_release_playlist_internal( p_playlist );
     return 1;
 }
diff --git a/modules/misc/notify/telepathy.c b/modules/misc/notify/telepathy.c
index b6c01c8..c89c587 100644
--- a/modules/misc/notify/telepathy.c
+++ b/modules/misc/notify/telepathy.c
@@ -173,17 +173,17 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     playlist_t* p_playlist = (playlist_t*) p_this;
     char *psz_buf = NULL;
     input_thread_t *p_input;
+    input_item_t *p_item = newval.p_address;
     bool b_is_item_current = !strcmp( "item-current", psz_var );
 
     /* Don't update Telepathy presence each time an item has been preparsed */
     if( b_is_item_current )
     { /* stores the current input item id */
-        p_intf->p_sys->i_id = newval.i_int;
+        p_intf->p_sys->i_id = p_item->i_id;
         p_intf->p_sys->i_item_changes = 0;
     }
     else
     {
-        input_item_t *p_item = newval.p_address;
 
         if( p_item->i_id != p_intf->p_sys->i_id ) /* "item-change" */
             return VLC_SUCCESS;
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index f5139fa..5b068b4 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -279,8 +279,7 @@ static void VariablesInit( playlist_t *p_playlist )
 
     var_Create( p_playlist, "playlist-item-append", VLC_VAR_ADDRESS );
 
-    var_Create( p_playlist, "item-current", VLC_VAR_INTEGER );
-    var_SetInteger( p_playlist, "item-current", -1 );
+    var_Create( p_playlist, "item-current", VLC_VAR_ADDRESS );
 
     var_Create( p_playlist, "activity", VLC_VAR_INTEGER );
     var_SetInteger( p_playlist, "activity", 0 );
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index eacfd37..3e7bf06 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -297,7 +297,7 @@ static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
     }
 
     PL_UNLOCK;
-    var_SetInteger( p_playlist, "item-current", p_input->i_id );
+    var_SetAddress( p_playlist, "item-current", p_input );
     PL_LOCK;
 
     return VLC_SUCCESS;




More information about the vlc-devel mailing list