[vlc-commits] skins2: remove playlist pointer copy and simplify

Rémi Denis-Courmont git at videolan.org
Fri Nov 18 23:06:32 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 19 00:06:17 2016 +0200| [6acc10eb1c3e1beba591b8a94ecd7e2c2d1a317d] | committer: Rémi Denis-Courmont

skins2: remove playlist pointer copy and simplify

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

 modules/gui/skins2/commands/cmd_add_item.cpp |  4 +-
 modules/gui/skins2/commands/cmd_audio.cpp    |  4 +-
 modules/gui/skins2/commands/cmd_dvd.cpp      | 15 +++----
 modules/gui/skins2/commands/cmd_input.cpp    | 38 +++++-------------
 modules/gui/skins2/commands/cmd_playlist.cpp | 54 +++++++++----------------
 modules/gui/skins2/commands/cmd_playtree.cpp |  2 +-
 modules/gui/skins2/commands/cmd_vars.cpp     |  2 +-
 modules/gui/skins2/src/skin_common.hpp       |  4 +-
 modules/gui/skins2/src/skin_main.cpp         |  3 +-
 modules/gui/skins2/src/vlcproc.cpp           | 59 +++++++++++-----------------
 modules/gui/skins2/vars/equalizer.cpp        |  6 +--
 modules/gui/skins2/vars/playtree.cpp         |  2 +-
 modules/gui/skins2/vars/volume.cpp           |  6 +--
 13 files changed, 66 insertions(+), 133 deletions(-)

diff --git a/modules/gui/skins2/commands/cmd_add_item.cpp b/modules/gui/skins2/commands/cmd_add_item.cpp
index d4635dd..eeb01e7 100644
--- a/modules/gui/skins2/commands/cmd_add_item.cpp
+++ b/modules/gui/skins2/commands/cmd_add_item.cpp
@@ -33,9 +33,7 @@
 
 void CmdAddItem::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( !pPlaylist )
-        return;
+    playlist_t *pPlaylist = getPL();
 
     if( strstr( m_name.c_str(), "://" ) == NULL )
     {
diff --git a/modules/gui/skins2/commands/cmd_audio.cpp b/modules/gui/skins2/commands/cmd_audio.cpp
index a74198d..b57a092 100644
--- a/modules/gui/skins2/commands/cmd_audio.cpp
+++ b/modules/gui/skins2/commands/cmd_audio.cpp
@@ -29,9 +29,7 @@
 
 void CmdSetEqualizer::execute()
 {
-    playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
-
-    playlist_EnableAudioFilter( pPlaylist, "equalizer", m_enable );
+    playlist_EnableAudioFilter( getPL(), "equalizer", m_enable );
 }
 
 
diff --git a/modules/gui/skins2/commands/cmd_dvd.cpp b/modules/gui/skins2/commands/cmd_dvd.cpp
index 6d6311a..9e9c5f8 100644
--- a/modules/gui/skins2/commands/cmd_dvd.cpp
+++ b/modules/gui/skins2/commands/cmd_dvd.cpp
@@ -27,8 +27,7 @@
 
 void CmdDvdNextTitle::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *p_input = playlist_CurrentInput( pPlaylist );
+    input_thread_t *p_input = playlist_CurrentInput( getPL() );
 
     if( p_input )
     {
@@ -40,8 +39,7 @@ void CmdDvdNextTitle::execute()
 
 void CmdDvdPreviousTitle::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *p_input = playlist_CurrentInput( pPlaylist );
+    input_thread_t *p_input = playlist_CurrentInput( getPL() );
 
     if( p_input )
     {
@@ -53,8 +51,7 @@ void CmdDvdPreviousTitle::execute()
 
 void CmdDvdNextChapter::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *p_input = playlist_CurrentInput( pPlaylist );
+    input_thread_t *p_input = playlist_CurrentInput( getPL() );
 
     if( p_input )
     {
@@ -66,8 +63,7 @@ void CmdDvdNextChapter::execute()
 
 void CmdDvdPreviousChapter::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *p_input = playlist_CurrentInput( pPlaylist );
+    input_thread_t *p_input = playlist_CurrentInput( getPL() );
 
     if( p_input )
     {
@@ -79,8 +75,7 @@ void CmdDvdPreviousChapter::execute()
 
 void CmdDvdRootMenu::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *p_input = playlist_CurrentInput( pPlaylist );
+    input_thread_t *p_input = playlist_CurrentInput( getPL() );
 
     if( p_input )
     {
diff --git a/modules/gui/skins2/commands/cmd_input.cpp b/modules/gui/skins2/commands/cmd_input.cpp
index c78c790..e0a6ecf 100644
--- a/modules/gui/skins2/commands/cmd_input.cpp
+++ b/modules/gui/skins2/commands/cmd_input.cpp
@@ -29,15 +29,13 @@
 
 void CmdPlay::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist == NULL )
-        return;
+    playlist_t *pPlaylist = getPL();
 
     // if already playing an input, reset rate to normal speed
     input_thread_t *pInput = playlist_CurrentInput( pPlaylist );
     if( pInput )
     {
-        var_SetFloat( pPlaylist, "rate", 1.0 );
+        var_SetFloat( getPL(), "rate", 1.0 );
         vlc_object_release( pInput );
     }
 
@@ -59,60 +57,42 @@ void CmdPlay::execute()
 
 void CmdPause::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        playlist_TogglePause( pPlaylist );
+    playlist_TogglePause( getPL() );
 }
 
 
 void CmdStop::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        playlist_Stop( pPlaylist );
+    playlist_Stop( getPL() );
 }
 
 
 void CmdSlower::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *pInput = playlist_CurrentInput( pPlaylist );
-
-    if( pInput )
-    {
-        var_TriggerCallback( pPlaylist, "rate-slower" );
-        vlc_object_release( pInput );
-    }
+    var_TriggerCallback( getPL(), "rate-slower" );
 }
 
 
 void CmdFaster::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    input_thread_t *pInput = playlist_CurrentInput( pPlaylist );
-
-    if( pInput )
-    {
-        var_TriggerCallback( pPlaylist, "rate-faster" );
-        vlc_object_release( pInput );
-    }
+    var_TriggerCallback( getPL(), "rate-faster" );
 }
 
 
 void CmdMute::execute()
 {
-    playlist_MuteToggle( getIntf()->p_sys->p_playlist );
+    playlist_MuteToggle( getPL() );
 }
 
 
 void CmdVolumeUp::execute()
 {
-    playlist_VolumeUp( getIntf()->p_sys->p_playlist, 1, NULL );
+    playlist_VolumeUp( getPL(), 1, NULL );
 }
 
 
 void CmdVolumeDown::execute()
 {
-    playlist_VolumeDown( getIntf()->p_sys->p_playlist, 1, NULL );
+    playlist_VolumeDown( getPL(), 1, NULL );
 }
 
diff --git a/modules/gui/skins2/commands/cmd_playlist.cpp b/modules/gui/skins2/commands/cmd_playlist.cpp
index 7cfe8d5..dc38840 100644
--- a/modules/gui/skins2/commands/cmd_playlist.cpp
+++ b/modules/gui/skins2/commands/cmd_playlist.cpp
@@ -34,75 +34,59 @@ void CmdPlaylistDel::execute()
 
 void CmdPlaylistNext::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        playlist_Next( pPlaylist );
+    playlist_Next( getPL() );
 }
 
 
 void CmdPlaylistPrevious::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        playlist_Prev( pPlaylist );
+    playlist_Prev( getPL() );
 }
 
 
 void CmdPlaylistRandom::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        var_SetBool( pPlaylist , "random", m_value );
+    var_SetBool( getPL(), "random", m_value );
 }
 
 
 void CmdPlaylistLoop::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        var_SetBool( pPlaylist , "loop", m_value );
+    var_SetBool( getPL(), "loop", m_value );
 }
 
 
 void CmdPlaylistRepeat::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        var_SetBool( pPlaylist , "repeat", m_value );
+    var_SetBool( getPL(), "repeat", m_value );
 }
 
 
 void CmdPlaylistLoad::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
-        playlist_Import( pPlaylist, m_file.c_str() );
+    playlist_Import( getPL(), m_file.c_str() );
 }
 
 
 void CmdPlaylistSave::execute()
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    if( pPlaylist != NULL )
+    const char *psz_module;
+    if( m_file.find( ".xsp", 0 ) != std::string::npos )
+        psz_module = "export-xspf";
+    else if( m_file.find( "m3u", 0 ) != std::string::npos )
+        psz_module = "export-m3u";
+    else if( m_file.find( "html", 0 ) != std::string::npos )
+        psz_module = "export-html";
+    else
     {
-        const char *psz_module;
-        if( m_file.find( ".xsp", 0 ) != std::string::npos )
-            psz_module = "export-xspf";
-        else if( m_file.find( "m3u", 0 ) != std::string::npos )
-            psz_module = "export-m3u";
-        else if( m_file.find( "html", 0 ) != std::string::npos )
-            psz_module = "export-html";
-        else
-        {
-            msg_Err(getIntf(),"Did not recognise playlist export file type");
-            return;
-        }
-
-        playlist_Export( pPlaylist, m_file.c_str(), true, psz_module );
+        msg_Err(getIntf(),"Did not recognise playlist export file type");
+        return;
     }
+
+    playlist_Export( getPL(), m_file.c_str(), true, psz_module );
 }
 
 void CmdPlaylistFirst::execute()
 {
-    playlist_Control(getIntf()->p_sys->p_playlist,PLAYLIST_PLAY,pl_Unlocked);
+    playlist_Control(getPL(), PLAYLIST_PLAY, pl_Unlocked);
 }
diff --git a/modules/gui/skins2/commands/cmd_playtree.cpp b/modules/gui/skins2/commands/cmd_playtree.cpp
index 8f26630..dbbfd2c 100644
--- a/modules/gui/skins2/commands/cmd_playtree.cpp
+++ b/modules/gui/skins2/commands/cmd_playtree.cpp
@@ -36,7 +36,7 @@ void CmdPlaytreeSort::execute()
 {
     /// \todo Choose sort method/order - Need more commands
     /// \todo Choose the correct view
-    playlist_t *p_playlist = getIntf()->p_sys->p_playlist;
+    playlist_t *p_playlist = getPL();
     PL_LOCK;
     playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root,
                                 SORT_TITLE, ORDER_NORMAL );
diff --git a/modules/gui/skins2/commands/cmd_vars.cpp b/modules/gui/skins2/commands/cmd_vars.cpp
index 7efdc28..2da80a2 100644
--- a/modules/gui/skins2/commands/cmd_vars.cpp
+++ b/modules/gui/skins2/commands/cmd_vars.cpp
@@ -34,7 +34,7 @@ void CmdItemUpdate::execute()
         return;
 
     // update playtree
-    playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
+    playlist_t* pPlaylist = getPL();
     playlist_Lock( pPlaylist );
     playlist_item_t* p_plItem = playlist_ItemGetByInput( pPlaylist, m_pItem );
     int id = p_plItem ? p_plItem->i_id : 0;
diff --git a/modules/gui/skins2/src/skin_common.hpp b/modules/gui/skins2/src/skin_common.hpp
index 56c1ee8..d748e51 100644
--- a/modules/gui/skins2/src/skin_common.hpp
+++ b/modules/gui/skins2/src/skin_common.hpp
@@ -94,9 +94,6 @@ struct intf_sys_t
     /// The input thread
     input_thread_t *p_input;
 
-    /// The playlist thread
-    playlist_t *p_playlist;
-
     // "Singleton" objects: MUST be initialized to NULL !
     /// Logger
     Logger *p_logger;
@@ -143,6 +140,7 @@ public:
     /// Getter (public because it is used in C callbacks in the win32
     /// interface)
     intf_thread_t *getIntf() const { return m_pIntf; }
+    playlist_t *getPL() const { return pl_Get(m_pIntf); }
 
 private:
     intf_thread_t *m_pIntf;
diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp
index 8f3da3c..00c011a 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -83,7 +83,6 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
 
     p_intf->p_sys->p_input = NULL;
-    p_intf->p_sys->p_playlist = pl_Get( p_intf );
 
     // Initialize "singleton" objects
     p_intf->p_sys->p_logger = NULL;
@@ -150,7 +149,7 @@ static void Close( vlc_object_t *p_this )
     msg_Dbg( p_intf, "closing skins2 module" );
 
     /* Terminate input to ensure that our window provider is released. */
-    playlist_Deactivate( p_intf->p_sys->p_playlist );
+    playlist_Deactivate( pl_Get(p_intf) );
 
     vlc_mutex_lock( &skin_load.mutex );
     skin_load.intf = NULL;
diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index 6ead14c..b8d8c85 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -154,29 +154,25 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
 #define ADD_CALLBACK( p_object, var ) \
     var_AddCallback( p_object, var, onGenericCallback, this );
 
-    ADD_CALLBACK( pIntf->p_sys->p_playlist, "volume" )
-    ADD_CALLBACK( pIntf->p_sys->p_playlist, "mute" )
+    ADD_CALLBACK( getPL(), "volume" )
+    ADD_CALLBACK( getPL(), "mute" )
     ADD_CALLBACK( pIntf->obj.libvlc, "intf-toggle-fscontrol" )
 
-    ADD_CALLBACK( pIntf->p_sys->p_playlist, "random" )
-    ADD_CALLBACK( pIntf->p_sys->p_playlist, "loop" )
-    ADD_CALLBACK( pIntf->p_sys->p_playlist, "repeat" )
+    ADD_CALLBACK( getPL(), "random" )
+    ADD_CALLBACK( getPL(), "loop" )
+    ADD_CALLBACK( getPL(), "repeat" )
 
 #undef ADD_CALLBACK
 
     // Called when a playlist item is added
-    var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-append",
-                     onItemAppend, this );
+    var_AddCallback( getPL(), "playlist-item-append", onItemAppend, this );
     // Called when a playlist item is deleted
     // TODO: properly handle item-deleted
-    var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-deleted",
-                     onItemDelete, this );
+    var_AddCallback( getPL(), "playlist-item-deleted", onItemDelete, this );
     // Called when the current input changes
-    var_AddCallback( pIntf->p_sys->p_playlist, "input-current",
-                     onInputNew, this );
+    var_AddCallback( getPL(), "input-current", onInputNew, this );
     // Called when a playlist item changed
-    var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
-                     onItemChange, this );
+    var_AddCallback( getPL(), "item-change", onItemChange, this );
 
     // Called when we have an interaction dialog to display
     var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
@@ -195,29 +191,20 @@ VlcProc::~VlcProc()
         m_pVout = NULL;
     }
 
-    var_DelCallback( getIntf()->p_sys->p_playlist, "volume",
-                     onGenericCallback, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "mute",
-                     onGenericCallback, this );
+    var_DelCallback( getPL(), "volume", onGenericCallback, this );
+    var_DelCallback( getPL(), "mute",onGenericCallback, this );
     var_DelCallback( getIntf()->obj.libvlc, "intf-toggle-fscontrol",
                      onGenericCallback, this );
 
-    var_DelCallback( getIntf()->p_sys->p_playlist, "random",
-                     onGenericCallback, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
-                     onGenericCallback, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
-                     onGenericCallback, this );
+    var_DelCallback( getPL(), "random", onGenericCallback, this );
+    var_DelCallback( getPL(), "loop", onGenericCallback, this );
+    var_DelCallback( getPL(), "repeat", onGenericCallback, this );
 
-    var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
-                     onItemAppend, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
-                     onItemDelete, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
-                     onInputNew, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
-                     onItemChange, this );
-    var_DelCallback( getIntf(), "interaction", onInteraction, this );
+    var_DelCallback( getPL(), "playlist-item-append", onItemAppend, this );
+    var_DelCallback( getPL(), "playlist-item-deleted", onItemDelete, this );
+    var_DelCallback( getPL(), "input-current", onInputNew, this );
+    var_DelCallback( getPL(), "item-change", onItemChange, this );
+    var_DelCallback( getPL(), "interaction", onInteraction, this );
 }
 
 int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
@@ -620,9 +607,8 @@ void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
 {
     (void)p_obj; (void)newVal;
-    playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
 
-    SET_VOLUME( m_cVarVolume, var_GetFloat( pPlaylist, "volume" ), false );
+    SET_VOLUME( m_cVarVolume, var_GetFloat( getPL(), "volume" ), false );
 }
 
 void VlcProc::on_mute_changed( vlc_object_t* p_obj, vlc_value_t newVal )
@@ -715,7 +701,7 @@ void VlcProc::reset_input()
 
 void VlcProc::init_variables()
 {
-    playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
+    playlist_t* pPlaylist = getPL();
 
     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
@@ -769,8 +755,7 @@ void VlcProc::update_current_input()
 
 void VlcProc::init_equalizer()
 {
-    playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
-    audio_output_t* pAout = playlist_GetAout( pPlaylist );
+    audio_output_t* pAout = playlist_GetAout( getPL() );
     if( pAout )
     {
         if( !var_Type( pAout, "equalizer-bands" ) )
diff --git a/modules/gui/skins2/vars/equalizer.cpp b/modules/gui/skins2/vars/equalizer.cpp
index a61b1fc..8813d0b 100644
--- a/modules/gui/skins2/vars/equalizer.cpp
+++ b/modules/gui/skins2/vars/equalizer.cpp
@@ -84,8 +84,7 @@ VariablePtr EqualizerBands::getBand( int band )
 void EqualizerBands::onUpdate( Subject<VarPercent> &rBand, void *arg )
 {
     (void)rBand; (void)arg;
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    audio_output_t *pAout = playlist_GetAout( pPlaylist );
+    audio_output_t *pAout = playlist_GetAout( getPL() );
 
     // Make sure we are not called from set()
     if (!m_isUpdating)
@@ -128,8 +127,7 @@ EqualizerPreamp::EqualizerPreamp( intf_thread_t *pIntf ): VarPercent( pIntf )
 
 void EqualizerPreamp::set( float percentage, bool updateVLC )
 {
-    playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
-    audio_output_t *pAout = playlist_GetAout( pPlaylist );
+    audio_output_t *pAout = playlist_GetAout( getPL() );
 
     VarPercent::set( percentage );
 
diff --git a/modules/gui/skins2/vars/playtree.cpp b/modules/gui/skins2/vars/playtree.cpp
index 4005ced..7c47db2 100644
--- a/modules/gui/skins2/vars/playtree.cpp
+++ b/modules/gui/skins2/vars/playtree.cpp
@@ -36,7 +36,7 @@
 #include "../utils/ustring.hpp"
 
 Playtree::Playtree( intf_thread_t *pIntf )
-    : VarTree( pIntf ), m_pPlaylist( pIntf->p_sys->p_playlist )
+    : VarTree( pIntf ), m_pPlaylist( pl_Get(pIntf) )
 {
     getPositionVar().addObserver( this );
     buildTree();
diff --git a/modules/gui/skins2/vars/volume.cpp b/modules/gui/skins2/vars/volume.cpp
index 997daf1..4a0072c 100644
--- a/modules/gui/skins2/vars/volume.cpp
+++ b/modules/gui/skins2/vars/volume.cpp
@@ -39,8 +39,7 @@ Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf )
              / (float)AOUT_VOLUME_MAX;
 
     // set current volume from the playlist
-    playlist_t* pPlaylist = pIntf->p_sys->p_playlist;
-    setVolume( var_GetFloat( pPlaylist, "volume" ), false );
+    setVolume( var_GetFloat( getPL(), "volume" ), false );
 }
 
 
@@ -49,8 +48,7 @@ void Volume::set( float percentage, bool updateVLC )
     VarPercent::set( percentage );
     if( updateVLC )
     {
-        playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
-        playlist_VolumeSet( pPlaylist, getVolume() );
+        playlist_VolumeSet( getPL(), getVolume() );
     }
 }
 



More information about the vlc-commits mailing list