[vlc-devel] [PATCH 5/5] input_manager: Remove PLEvent boilerplate.

Hugo Beauzée-Luyssen hugo at beauzee.fr
Sun Dec 6 11:49:10 CET 2015


This fixes late events propagation, and fix the endlessly bouncing
buffering slider.
As a side effect, playlist events need to be queued to avoid recursive playlist
locks, which replicates the previous behavior, since the PLevent were queued
through postEvent.
---
 .../gui/qt4/components/playlist/playlist_model.cpp |  4 +-
 modules/gui/qt4/components/playlist/selector.cpp   |  4 +-
 modules/gui/qt4/input_manager.cpp                  | 97 ++++++----------------
 modules/gui/qt4/input_manager.hpp                  | 38 +++------
 modules/gui/qt4/qt4.hpp                            |  1 -
 5 files changed, 40 insertions(+), 104 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 3734efb..34c02ee 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -61,9 +61,9 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
               this, processInputItemUpdate( input_item_t *) );
     DCONNECT( THEMIM, inputChanged( bool ),
               this, processInputItemUpdate( ) );
-    CONNECT( THEMIM, playlistItemAppended( int, int ),
+    QCONNECT( THEMIM, playlistItemAppended( int, int ),
              this, processItemAppend( int, int ) );
-    CONNECT( THEMIM, playlistItemRemoved( int ),
+    QCONNECT( THEMIM, playlistItemRemoved( int ),
              this, processItemRemoval( int ) );
 }
 
diff --git a/modules/gui/qt4/components/playlist/selector.cpp b/modules/gui/qt4/components/playlist/selector.cpp
index 41ad88d..a584b88 100644
--- a/modules/gui/qt4/components/playlist/selector.cpp
+++ b/modules/gui/qt4/components/playlist/selector.cpp
@@ -135,9 +135,9 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
     podcastsParentId = -1;
 
     /* Podcast connects */
-    CONNECT( THEMIM, playlistItemAppended( int, int ),
+    QCONNECT( THEMIM, playlistItemAppended( int, int ),
              this, plItemAdded( int, int ) );
-    CONNECT( THEMIM, playlistItemRemoved( int ),
+    QCONNECT( THEMIM, playlistItemRemoved( int ),
              this, plItemRemoved( int ) );
     DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
               this, inputItemUpdate( input_item_t * ) );
diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index e9ca8fc..f873caa 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -45,15 +45,6 @@
 
 static int ItemChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
-static int LeafToParent( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-static int PLItemChanged( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-static int PLItemAppended( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-static int PLItemRemoved( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
-
 static int InputEvent( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
 static int VbiEvent( vlc_object_t *, const char *,
@@ -88,7 +79,6 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
     timeB        = 0;
     f_cache      = -1.; /* impossible initial value, different from all */
     registerAndCheckEventIds( IMEvent::PositionUpdate, IMEvent::FullscreenControlPlanHide );
-    registerAndCheckEventIds( PLEvent::PLItemAppended, PLEvent::PLEmpty );
 }
 
 InputManager::~InputManager()
@@ -1021,10 +1011,10 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
 
     /* Core Callbacks */
     var_AddCallback( THEPL, "item-change", ItemChanged, im );
-    var_AddCallback( THEPL, "input-current", PLItemChanged, this );
-    var_AddCallback( THEPL, "leaf-to-parent", LeafToParent, this );
-    var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
-    var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
+    var_AddCallback( THEPL, "input-current", MainInputManager::PLItemChanged, this );
+    var_AddCallback( THEPL, "leaf-to-parent", MainInputManager::LeafToParent, this );
+    var_AddCallback( THEPL, "playlist-item-append", MainInputManager::PLItemAppended, this );
+    var_AddCallback( THEPL, "playlist-item-deleted", MainInputManager::PLItemRemoved, this );
 
     /* Core Callbacks to widget */
     random.addCallback( this, SLOT(notifyRandom(bool)) );
@@ -1047,12 +1037,12 @@ MainInputManager::~MainInputManager()
        emit inputChanged( false );
     }
 
-    var_DelCallback( THEPL, "input-current", PLItemChanged, this );
+    var_DelCallback( THEPL, "input-current", MainInputManager::PLItemChanged, this );
     var_DelCallback( THEPL, "item-change", ItemChanged, im );
-    var_DelCallback( THEPL, "leaf-to-parent", LeafToParent, this );
+    var_DelCallback( THEPL, "leaf-to-parent", MainInputManager::LeafToParent, this );
 
-    var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
-    var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
+    var_DelCallback( THEPL, "playlist-item-append", MainInputManager::PLItemAppended, this );
+    var_DelCallback( THEPL, "playlist-item-deleted", MainInputManager::PLItemRemoved, this );
 
     delete menusAudioMapper;
 }
@@ -1067,41 +1057,6 @@ audio_output_t * MainInputManager::getAout()
     return playlist_GetAout( THEPL );
 }
 
-void MainInputManager::customEvent( QEvent *event )
-{
-    int type = event->type();
-
-    PLEvent *plEv;
-
-    // msg_Dbg( p_intf, "New MainIM Event of type: %i", type );
-    switch( type )
-    {
-    case PLEvent::PLItemAppended:
-        plEv = static_cast<PLEvent*>( event );
-        emit playlistItemAppended( plEv->getItemId(), plEv->getParentId() );
-        return;
-    case PLEvent::PLItemRemoved:
-        plEv = static_cast<PLEvent*>( event );
-        emit playlistItemRemoved( plEv->getItemId() );
-        return;
-    case PLEvent::PLEmpty:
-        plEv = static_cast<PLEvent*>( event );
-        emit playlistNotEmpty( plEv->getItemId() >= 0 );
-        return;
-    case PLEvent::LeafToParent:
-        plEv = static_cast<PLEvent*>( event );
-        emit leafBecameParent( plEv->getItemId() );
-        return;
-    default:
-        if( type != IMEvent::ItemChanged ) return;
-    }
-
-    if( p_input != NULL )
-        vlc_object_release( p_input );
-    p_input = playlist_CurrentInput( THEPL );
-    emit inputChanged( p_input != NULL );
-}
-
 /* Playlist Control functions */
 void MainInputManager::stop()
 {
@@ -1210,7 +1165,7 @@ bool MainInputManager::hasEmptyPlaylist()
 /****************************
  * Static callbacks for MIM *
  ****************************/
-static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
+int MainInputManager::PLItemChanged( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t val, void *param )
 {
     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
@@ -1218,20 +1173,20 @@ static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
 
     MainInputManager *mim = (MainInputManager*)param;
 
-    IMEvent *event = new IMEvent( IMEvent::ItemChanged );
-    QApplication::postEvent( mim, event );
+    if( mim->p_input != NULL )
+        vlc_object_release( mim->p_input );
+    mim->p_input = playlist_CurrentInput( mim->THEPL );
+    mim->emit inputChanged( mim->p_input != NULL );
     return VLC_SUCCESS;
 }
 
-static int LeafToParent( vlc_object_t *p_this, const char *psz_var,
+int MainInputManager::LeafToParent( vlc_object_t *p_this, const char *psz_var,
                         vlc_value_t oldval, vlc_value_t newval, void *param )
 {
     VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
-    MainInputManager *mim = (MainInputManager*)param;
 
-    PLEvent *event = new PLEvent( PLEvent::LeafToParent, newval.i_int );
-
-    QApplication::postEvent( mim, event );
+    MainInputManager *mim = (MainInputManager*)param;
+    mim->emit leafBecameParent( newval.i_int );
     return VLC_SUCCESS;
 }
 
@@ -1256,35 +1211,31 @@ void MainInputManager::menusUpdateAudio( const QString& data )
     }
 }
 
-static int PLItemAppended
-( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
+int MainInputManager::PLItemAppended( vlc_object_t * obj, const char *var,
+                                             vlc_value_t old, vlc_value_t cur, void *data )
 {
     VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
     MainInputManager *mim = static_cast<MainInputManager*>(data);
     playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
 
-    PLEvent *event = new PLEvent( PLEvent::PLItemAppended, p_add->i_item, p_add->i_node  );
-    QApplication::postEvent( mim, event );
-    event = new PLEvent( PLEvent::PLEmpty, p_add->i_item, 0  );
-    QApplication::postEvent( mim, event );
+    mim->emit playlistItemAppended( p_add->i_item, p_add->i_node );
+    mim->emit playlistNotEmpty( p_add->i_item );
     return VLC_SUCCESS;
 }
 
-static int PLItemRemoved
-( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
+int MainInputManager::PLItemRemoved( vlc_object_t * obj, const char *var,
+                                            vlc_value_t old, vlc_value_t cur, void *data )
 {
     VLC_UNUSED( var ); VLC_UNUSED( old );
 
     playlist_t *pl = (playlist_t *) obj;
     MainInputManager *mim = static_cast<MainInputManager*>(data);
 
-    PLEvent *event = new PLEvent( PLEvent::PLItemRemoved, cur.i_int, 0  );
-    QApplication::postEvent( mim, event );
+    mim->emit playlistItemRemoved( cur.i_int );
     // can't use playlist_IsEmpty(  ) as it isn't true yet
     if ( pl->items.i_size == 1 ) // lock is held
     {
-        event = new PLEvent( PLEvent::PLEmpty, -1, 0 );
-        QApplication::postEvent( mim, event );
+        mim->emit playlistNotEmpty( false );
     }
     return VLC_SUCCESS;
 }
diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp
index 8a0d2c3..275f1b1 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -96,30 +96,6 @@ private:
     input_item_t *p_item;
 };
 
-class PLEvent : public QEvent
-{
-public:
-    enum PLEventTypes
-    {
-        PLItemAppended = QEvent::User + PLEventTypeOffset + 1,
-        PLItemRemoved,
-        LeafToParent,
-        PLEmpty
-    };
-
-    PLEvent( PLEventTypes t, int i, int p = 0 )
-        : QEvent( (QEvent::Type)(t) ), i_item(i), i_parent(p) {}
-    int getItemId() const { return i_item; };
-    int getParentId() const { return i_parent; };
-
-private:
-    /* Needed for "playlist-item*" and "leaf-to-parent" callbacks
-     * !! Can be a input_item_t->i_id or a playlist_item_t->i_id */
-    int i_item;
-    // Needed for "playlist-item-append" callback, notably
-    int i_parent;
-};
-
 class InputManager : public QObject
 {
     Q_OBJECT
@@ -276,11 +252,21 @@ protected:
     QSignalMapper *menusAudioMapper;
 
 private:
+    static int PLItemChanged( vlc_object_t *, const char *,
+                            vlc_value_t, vlc_value_t, void * );
+    static int LeafToParent( vlc_object_t *, const char *,
+                            vlc_value_t, vlc_value_t, void * );
+    static int PLItemAppended( vlc_object_t *, const char *,
+                            vlc_value_t, vlc_value_t, void * );
+    static int PLItemRemoved( vlc_object_t *, const char *,
+                            vlc_value_t, vlc_value_t, void * );
+
+
+
+private:
     MainInputManager( intf_thread_t * );
     virtual ~MainInputManager();
 
-    void customEvent( QEvent * );
-
     InputManager            *im;
     input_thread_t          *p_input;
     intf_thread_t           *p_intf;
diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp
index 535d3fe..a42baaf 100644
--- a/modules/gui/qt4/qt4.hpp
+++ b/modules/gui/qt4/qt4.hpp
@@ -57,7 +57,6 @@
 enum {
     DialogEventTypeOffset = 0,
     IMEventTypeOffset     = 100,
-    PLEventTypeOffset     = 200,
     MsgEventTypeOffset    = 300,
 };
 
-- 
2.6.2



More information about the vlc-devel mailing list