]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/vlcproc.cpp
skins2: use the vout window interface (untested)
[vlc] / modules / gui / skins2 / src / vlcproc.cpp
index 92e8fa0f0e2da91305f05950a6f78ec9998524a6..bf2ef4f681e69601a81dc9012274d82087ffc720 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulie <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <vlc/aout.h>
-#include <vlc/vout.h>
-#include <aout_internal.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_vout.h>
+#include <vlc_playlist.h>
+#include <vlc_window.h>
 
 #include "vlcproc.hpp"
 #include "os_factory.hpp"
@@ -79,11 +85,6 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
 #define REGISTER_VAR( var, type, name ) \
     var = VariablePtr( new type( getIntf() ) ); \
     pVarManager->registerVar( var, name );
-
-    /* Playlist variables */
-    REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
-    pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
-                              "playlist.slider" );
     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
@@ -108,6 +109,7 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
 
     /* Aout variables */
+    REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
     REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
@@ -147,7 +149,7 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
                      onItemDelete, this );
     // Called when the "interface shower" wants us to show the skin
-    var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
+    var_AddCallback( pIntf->p_libvlc, "intf-show",
                      onIntfShow, this );
     // Called when the current played item changes
     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
@@ -161,12 +163,7 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
     // Called when we have an interaction dialog to display
     var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
     var_AddCallback( pIntf, "interaction", onInteraction, this );
-    pIntf->b_interaction = VLC_TRUE;
-
-    // Callbacks for vout requests
-    getIntf()->pf_request_window = &getWindow;
-    getIntf()->pf_release_window = &releaseWindow;
-    getIntf()->pf_control_window = &controlWindow;
+    pIntf->b_interaction = true;
 
     getIntf()->p_sys->p_input = NULL;
 }
@@ -181,18 +178,13 @@ VlcProc::~VlcProc()
         vlc_object_release( getIntf()->p_sys->p_input );
     }
 
-    // Callbacks for vout requests
-    getIntf()->pf_request_window = NULL;
-    getIntf()->pf_release_window = NULL;
-    getIntf()->pf_control_window = NULL;
-
     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
                      onIntfChange, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "item-append",
                      onItemAppend, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "item-deleted",
                      onItemDelete, this );
-    var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
+    var_DelCallback( getIntf()->p_libvlc, "intf-show",
                      onIntfShow, this );
     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
                      onPlaylistChange, this );
@@ -208,7 +200,7 @@ void VlcProc::registerVoutWindow( void *pVoutWindow )
     // Reparent the vout window
     if( m_pVout )
     {
-        if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
+        if( vout_Control( m_pVout, VOUT_REPARENT, 0 ) != VLC_SUCCESS )
             vout_Control( m_pVout, VOUT_CLOSE );
     }
 }
@@ -224,7 +216,7 @@ void VlcProc::dropVout()
 {
     if( m_pVout )
     {
-        if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
+        if( vout_Control( m_pVout, VOUT_REPARENT, 0 ) != VLC_SUCCESS )
             vout_Control( m_pVout, VOUT_CLOSE );
         m_pVout = NULL;
     }
@@ -234,30 +226,104 @@ void VlcProc::dropVout()
 void VlcProc::manage()
 {
     // Did the user request to quit vlc ?
-    if( getIntf()->b_die || getIntf()->p_vlc->b_die )
+    if( intf_ShouldDie( getIntf() ) )
     {
         CmdQuit *pCmd = new CmdQuit( getIntf() );
         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
         pQueue->push( CmdGenericPtr( pCmd ) );
     }
 
-    // Get the VLC variables
-    StreamTime *pTime = (StreamTime*)m_cVarTime.get();
-    VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
-    VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
-    VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
-    VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
+    refreshPlaylist();
+    refreshAudio();
+    refreshInput();
+}
+void VlcProc::CmdManage::execute()
+{
+    // Just forward to VlcProc
+    m_pParent->manage();
+}
+
+void VlcProc::refreshAudio()
+{
+    char *pFilters;
+
+    // Check if the audio output has changed
+    aout_instance_t *pAout = (aout_instance_t *)vlc_object_find( getIntf(),
+            VLC_OBJECT_AOUT, FIND_ANYWHERE );
+    if( pAout )
+    {
+        if( pAout != m_pAout )
+        {
+            // Register the equalizer callbacks
+            if( !var_AddCallback( pAout, "equalizer-bands",
+                                  onEqBandsChange, this ) &&
+                !var_AddCallback( pAout, "equalizer-preamp",
+                                  onEqPreampChange, this ) )
+            {
+                m_pAout = pAout;
+                //char * psz_bands = var_GetString( p_aout, "equalizer-bands" );
+            }
+        }
+        // Get the audio filters
+        pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
+        vlc_object_release( pAout );
+    }
+    else
+    {
+        // Get the audio filters
+        pFilters = config_GetPsz( getIntf(), "audio-filter" );
+    }
+
+    // Refresh sound volume
+    audio_volume_t volume;
+    aout_VolumeGet( getIntf(), &volume );
+    Volume *pVolume = (Volume*)m_cVarVolume.get();
+    pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX );
+
+    // Set the mute variable
+    VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
+    pVarMute->set( volume == 0 );
+
+    // Refresh the equalizer variable
+    VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
+    pVarEqualizer->set( pFilters && strstr( pFilters, "equalizer" ) );
+    free( pFilters );
+}
+
+void VlcProc::refreshPlaylist()
+{
+    // Refresh the random variable
     VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
+    vlc_value_t val;
+    var_Get( getIntf()->p_sys->p_playlist, "random", &val );
+    pVarRandom->set( val.b_bool != 0 );
+
+    // Refresh the loop variable
     VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
+    var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
+    pVarLoop->set( val.b_bool != 0 );
+
+    // Refresh the repeat variable
     VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
+    var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
+    pVarRepeat->set( val.b_bool != 0 );
+}
+
+void VlcProc::refreshInput()
+{
+    StreamTime *pTime = (StreamTime*)m_cVarTime.get();
+    VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
     VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
-    VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
     VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
+    VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get();
     VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get();
     VarText *pSampleRate = (VarText*)m_cVarStreamSampleRate.get();
+    VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
+    VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
+    VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
+    VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
 
-    // Refresh audio variables
-    refreshAudio();
+    input_thread_t *pInput = getIntf()->p_sys->p_input;
 
     // Update the input
     if( getIntf()->p_sys->p_input == NULL )
@@ -272,7 +338,6 @@ void VlcProc::manage()
         getIntf()->p_sys->p_input = NULL;
     }
 
-    input_thread_t *pInput = getIntf()->p_sys->p_input;
 
     if( pInput && !pInput->b_die )
     {
@@ -280,26 +345,31 @@ void VlcProc::manage()
         vlc_value_t pos;
         var_Get( pInput, "position", &pos );
         pTime->set( pos.f_float, false );
-
-        // Get the status of the playlist
-        playlist_status_t status =
-            getIntf()->p_sys->p_playlist->status.i_status;
-
-        pVarPlaying->set( status == PLAYLIST_RUNNING );
-        pVarStopped->set( status == PLAYLIST_STOPPED );
-        pVarPaused->set( status == PLAYLIST_PAUSED );
-
         pVarSeekable->set( pos.f_float != 0.0 );
 
         // Refresh DVD detection
         vlc_value_t chapters_count;
         var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
-                    &chapters_count, NULL );
+                        &chapters_count, NULL );
         pVarDvdActive->set( chapters_count.i_int > 0 );
 
+        // Get the input bitrate
+        int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
+        pBitrate->set( UString::fromInt( getIntf(), bitrate ) );
+
+        // Get the audio sample rate
+        int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
+        pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );
+
+        // Do we have audio
+        vlc_value_t audio_es;
+        var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
+                        &audio_es, NULL );
+        pVarHasAudio->set( audio_es.i_int > 0 );
+
         // Refresh fullscreen status
         vout_thread_t *pVout = (vout_thread_t *)vlc_object_find( pInput,
-                VLC_OBJECT_VOUT, FIND_CHILD );
+                                     VLC_OBJECT_VOUT, FIND_CHILD );
         pVarHasVout->set( pVout != NULL );
         if( pVout )
         {
@@ -307,97 +377,26 @@ void VlcProc::manage()
             vlc_object_release( pVout );
         }
 
-        // Get the input bitrate
-        int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
-        pBitrate->set( UString::fromInt( getIntf(), bitrate ) );
-
-        // Get the audio sample rate
-        int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
-        pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );
+        // Refresh play/pause status
+        int state = var_GetInteger( pInput, "state" );
+        pVarStopped->set( false );
+        pVarPlaying->set( state != PAUSE_S );
+        pVarPaused->set( state == PAUSE_S );
     }
     else
     {
-        pVarPlaying->set( false );
-        pVarPaused->set( false );
-        pVarStopped->set( true );
         pVarSeekable->set( false );
         pVarDvdActive->set( false );
         pTime->set( 0, false );
         pVarFullscreen->set( false );
+        pVarHasAudio->set( false );
         pVarHasVout->set( false );
+        pVarStopped->set( true );
+        pVarPlaying->set( false );
+        pVarPaused->set( false );
     }
-
-    // Refresh the random variable
-    vlc_value_t val;
-    var_Get( getIntf()->p_sys->p_playlist, "random", &val );
-    pVarRandom->set( val.b_bool != 0 );
-
-    // Refresh the loop variable
-    var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
-    pVarLoop->set( val.b_bool != 0 );
-
-    // Refresh the repeat variable
-    var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
-    pVarRepeat->set( val.b_bool != 0 );
-
-
-}
-
-
-void VlcProc::CmdManage::execute()
-{
-    // Just forward to VlcProc
-    m_pParent->manage();
-}
-
-
-void VlcProc::refreshAudio()
-{
-    char *pFilters = NULL;
-
-    // Check if the audio output has changed
-    aout_instance_t *pAout = (aout_instance_t *)vlc_object_find( getIntf(),
-            VLC_OBJECT_AOUT, FIND_ANYWHERE );
-    if( pAout )
-    {
-        if( pAout != m_pAout )
-        {
-            // Register the equalizer callbacks
-            if( !var_AddCallback( pAout, "equalizer-bands",
-                                  onEqBandsChange, this ) &&
-                !var_AddCallback( pAout, "equalizer-preamp",
-                                  onEqPreampChange, this ) )
-            {
-                m_pAout = pAout;
-                //char * psz_bands = var_GetString( p_aout, "equalizer-bands" );
-            }
-        }
-        // Get the audio filters
-        pFilters = var_GetString( pAout, "audio-filter" );
-        vlc_object_release( pAout );
-    }
-    else
-    {
-        // Get the audio filters
-        pFilters = config_GetPsz( getIntf(), "audio-filter" );
-    }
-
-    // Refresh sound volume
-    audio_volume_t volume;
-    aout_VolumeGet( getIntf(), &volume );
-    Volume *pVolume = (Volume*)m_cVarVolume.get();
-    pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX );
-
-    // Set the mute variable
-    VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
-    pVarMute->set( volume == 0 );
-
-    // Refresh the equalizer variable
-    VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
-    pVarEqualizer->set( pFilters && strstr( pFilters, "equalizer" ) );
 }
 
-
 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
                            vlc_value_t oldVal, vlc_value_t newVal,
                            void *pParam )
@@ -408,14 +407,11 @@ int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
     playlist_t *p_playlist = (playlist_t*)pObj;
     pThis->updateStreamName(p_playlist);
 
-    // Create a playlist notify command (for old style playlist)
-    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
     // Create a playtree notify command (for new style playtree)
     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
 
     // Push the command in the asynchronous command queue
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
     pQueue->push( CmdGenericPtr( pCmdTree ) );
 
     return VLC_SUCCESS;
@@ -453,16 +449,12 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
     playlist_t *p_playlist = (playlist_t*)pObj;
     pThis->updateStreamName(p_playlist);
 
-    // Create a playlist notify command
-    // TODO: selective update
-    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
     // Create a playtree notify command
     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
                                                          newVal.i_int );
 
     // Push the command in the asynchronous command queue
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
     pQueue->push( CmdGenericPtr( pCmdTree ), true );
 
     return VLC_SUCCESS;
@@ -484,12 +476,8 @@ int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
                                                              p_add );
     ptrTree = CmdGenericPtr( pCmdTree );
 
-    // Create a playlist notify command (for old style playlist)
-    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
-
     // Push the command in the asynchronous command queue
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
     pQueue->push( ptrTree , false );
 
     return VLC_SUCCESS;
@@ -508,20 +496,14 @@ int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
                                                          i_id);
     ptrTree = CmdGenericPtr( pCmdTree );
 
-    // Create a playlist notify command (for old style playlist)
-    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
-
     // Push the command in the asynchronous command queue
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
     pQueue->push( ptrTree , false );
 
     return VLC_SUCCESS;
 }
 
 
-
-
 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
                                vlc_value_t oldVal, vlc_value_t newVal,
                                void *pParam )
@@ -534,10 +516,6 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
     playlist_t *p_playlist = (playlist_t*)pObj;
     pThis->updateStreamName(p_playlist);
 
-    // Create a playlist notify command (old style playlist)
-    // TODO: selective update
-    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
     // Create two playtree notify commands: one for old item, one for new
     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
                                                          oldVal.i_int );
@@ -585,7 +563,7 @@ void VlcProc::updateStreamName( playlist_t *p_playlist )
     if( p_playlist && p_playlist->p_input )
     {
         // Get playlist item information
-        input_item_t *pItem = p_playlist->p_input->input.p_item;
+        input_item_t *pItem = input_GetItem(p_playlist->p_input);
 
         VarText &rStreamName = getStreamNameVar();
         VarText &rStreamURI = getStreamURIVar();
@@ -620,13 +598,13 @@ void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
                           unsigned int *pHeightHint )
 {
     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
-    pThis->m_pVout = pVout;
     if( pThis->m_handleSet.empty() )
     {
         return NULL;
     }
     else
     {
+        pThis->m_pVout = pVout;
         // Get the window handle
         void *pWindow = *pThis->m_handleSet.begin();
         // Post a resize vout command
@@ -646,9 +624,10 @@ void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
 }
 
 
-int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
+int VlcProc::controlWindow( struct vout_window_t *pWnd,
                             int query, va_list args )
 {
+    intf_thread_t *pIntf = (intf_thread_t *)pWnd->p_private;
     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
 
     switch( query )
@@ -664,7 +643,7 @@ int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
 
                 // Post a resize vout command
                 CmdResizeVout *pCmd =
-                    new CmdResizeVout( pThis->getIntf(), pWindow,
+                    new CmdResizeVout( pThis->getIntf(), pWnd->handle,
                                        i_width, i_height );
                 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
                 pQueue->push( CmdGenericPtr( pCmd ) );
@@ -672,7 +651,7 @@ int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
         }
 
         default:
-            msg_Dbg( pIntf, "control query not supported" );
+            msg_Dbg( pWnd, "control query not supported" );
             break;
     }