Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vlcproc.cpp

00001 /*****************************************************************************
00002  * vlcproc.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: vlcproc.cpp 13051 2005-10-31 07:35:39Z md $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include <vlc/aout.h>
00026 #include <vlc/vout.h>
00027 
00028 #include "vlcproc.hpp"
00029 #include "os_factory.hpp"
00030 #include "os_timer.hpp"
00031 #include "var_manager.hpp"
00032 #include "theme.hpp"
00033 #include "window_manager.hpp"
00034 #include "../commands/async_queue.hpp"
00035 #include "../commands/cmd_change_skin.hpp"
00036 #include "../commands/cmd_show_window.hpp"
00037 #include "../commands/cmd_quit.hpp"
00038 #include "../commands/cmd_resize.hpp"
00039 #include "../commands/cmd_vars.hpp"
00040 #include "../utils/var_bool.hpp"
00041 
00042 
00043 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
00044 {
00045     if( pIntf->p_sys->p_vlcProc == NULL )
00046     {
00047         pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
00048     }
00049 
00050     return pIntf->p_sys->p_vlcProc;
00051 }
00052 
00053 
00054 void VlcProc::destroy( intf_thread_t *pIntf )
00055 {
00056     if( pIntf->p_sys->p_vlcProc )
00057     {
00058         delete pIntf->p_sys->p_vlcProc;
00059         pIntf->p_sys->p_vlcProc = NULL;
00060     }
00061 }
00062 
00063 
00064 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ), m_pVout( NULL ),
00065     m_cmdManage( this )
00066 {
00067     // Create a timer to poll the status of the vlc
00068     OSFactory *pOsFactory = OSFactory::instance( pIntf );
00069     m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
00070     m_pTimer->start( 100, false );
00071 
00072     // Create and register VLC variables
00073     VarManager *pVarManager = VarManager::instance( getIntf() );
00074 
00075 #define REGISTER_VAR( var, type, name ) \
00076     var = VariablePtr( new type( getIntf() ) ); \
00077     pVarManager->registerVar( var, name );
00078     REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
00079     pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
00080                               "playlist.slider" );
00081     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
00082     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
00083     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
00084     REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
00085     pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
00086                               "playtree.slider" );
00087     pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
00088     pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
00089     pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
00090     REGISTER_VAR( m_cVarTime, StreamTime, "time" )
00091     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
00092     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
00093     REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
00094     REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
00095     REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
00096     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
00097 #undef REGISTER_VAR
00098     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
00099     pVarManager->registerVar( m_cVarStreamName, "streamName" );
00100     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
00101     pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
00102 
00103     // XXX WARNING XXX
00104     // The object variable callbacks are called from other VLC threads,
00105     // so they must put commands in the queue and NOT do anything else
00106     // (X11 calls are not reentrant)
00107 
00108     // Called when the playlist changes
00109     var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
00110                      onIntfChange, this );
00111     // Called when a playlist item is added
00112     // TODO: properly handle item-append
00113     var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
00114                      onIntfChange, this );
00115     // Called when a playlist item is deleted
00116     // TODO: properly handle item-deleted
00117     var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
00118                      onIntfChange, this );
00119     // Called when the "interface shower" wants us to show the skin
00120     var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
00121                      onIntfShow, this );
00122     // Called when the current played item changes
00123     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
00124                      onPlaylistChange, this );
00125     // Called when a playlist item changed
00126     var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
00127                      onItemChange, this );
00128     // Called when our skins2 demux wants us to load a new skin
00129     var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
00130 
00131     // Callbacks for vout requests
00132     getIntf()->pf_request_window = &getWindow;
00133     getIntf()->pf_release_window = &releaseWindow;
00134     getIntf()->pf_control_window = &controlWindow;
00135 
00136     getIntf()->p_sys->p_input = NULL;
00137 }
00138 
00139 
00140 VlcProc::~VlcProc()
00141 {
00142     m_pTimer->stop();
00143     delete( m_pTimer );
00144     if( getIntf()->p_sys->p_input )
00145     {
00146         vlc_object_release( getIntf()->p_sys->p_input );
00147     }
00148 
00149     // Callbacks for vout requests
00150     getIntf()->pf_request_window = NULL;
00151     getIntf()->pf_release_window = NULL;
00152     getIntf()->pf_control_window = NULL;
00153 
00154     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
00155                      onIntfChange, this );
00156     var_DelCallback( getIntf()->p_sys->p_playlist, "item-append",
00157                      onIntfChange, this );
00158     var_DelCallback( getIntf()->p_sys->p_playlist, "item-deleted",
00159                      onIntfChange, this );
00160     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
00161                      onIntfShow, this );
00162     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
00163                      onPlaylistChange, this );
00164     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
00165                      onItemChange, this );
00166     var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
00167 }
00168 
00169 
00170 void VlcProc::registerVoutWindow( void *pVoutWindow )
00171 {
00172     m_handleSet.insert( pVoutWindow );
00173     // Reparent the vout window
00174     if( m_pVout )
00175     {
00176         if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
00177             vout_Control( m_pVout, VOUT_CLOSE );
00178     }
00179 }
00180 
00181 
00182 void VlcProc::unregisterVoutWindow( void *pVoutWindow )
00183 {
00184     m_handleSet.erase( pVoutWindow );
00185 }
00186 
00187 
00188 void VlcProc::dropVout()
00189 {
00190     if( m_pVout )
00191     {
00192         if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
00193             vout_Control( m_pVout, VOUT_CLOSE );
00194         m_pVout = NULL;
00195     }
00196 }
00197 
00198 
00199 void VlcProc::manage()
00200 {
00201     // Did the user requested to quit vlc ?
00202     if( getIntf()->b_die || getIntf()->p_vlc->b_die )
00203     {
00204         CmdQuit *pCmd = new CmdQuit( getIntf() );
00205         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
00206         pQueue->push( CmdGenericPtr( pCmd ) );
00207     }
00208 
00209     // Get the VLC variables
00210     StreamTime *pTime = (StreamTime*)m_cVarTime.get();
00211     Volume *pVolume = (Volume*)m_cVarVolume.get();
00212     VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
00213     VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
00214     VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
00215     VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
00216     VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
00217     VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
00218     VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
00219     VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
00220 
00221     // Refresh sound volume
00222     audio_volume_t volume;
00223     aout_VolumeGet( getIntf(), &volume );
00224     pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX );
00225     // Set the mute variable
00226     pVarMute->set( volume == 0 );
00227 
00228     // Update the input
00229     if( getIntf()->p_sys->p_input == NULL )
00230     {
00231         getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
00232             getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
00233     }
00234     else if( getIntf()->p_sys->p_input->b_dead )
00235     {
00236         vlc_object_release( getIntf()->p_sys->p_input );
00237         getIntf()->p_sys->p_input = NULL;
00238     }
00239 
00240     input_thread_t *pInput = getIntf()->p_sys->p_input;
00241 
00242     if( pInput && !pInput->b_die )
00243     {
00244         // Refresh time variables
00245         vlc_value_t pos;
00246         var_Get( pInput, "position", &pos );
00247         pTime->set( pos.f_float, false );
00248 
00249         // Get the status of the playlist
00250         playlist_status_t status =
00251             getIntf()->p_sys->p_playlist->status.i_status;
00252 
00253         pVarPlaying->set( status == PLAYLIST_RUNNING );
00254         pVarStopped->set( status == PLAYLIST_STOPPED );
00255         pVarPaused->set( status == PLAYLIST_PAUSED );
00256 
00257         pVarSeekable->set( pos.f_float != 0.0 );
00258     }
00259     else
00260     {
00261         pVarPlaying->set( false );
00262         pVarPaused->set( false );
00263         pVarStopped->set( true );
00264         pVarSeekable->set( false );
00265         pTime->set( 0, false );
00266     }
00267 
00268     // Refresh the random variable
00269     vlc_value_t val;
00270     var_Get( getIntf()->p_sys->p_playlist, "random", &val );
00271     pVarRandom->set( val.b_bool != 0 );
00272 
00273     // Refresh the loop variable
00274     var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
00275     pVarLoop->set( val.b_bool != 0 );
00276 
00277     // Refresh the repeat variable
00278     var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
00279     pVarRepeat->set( val.b_bool != 0 );
00280 }
00281 
00282 
00283 void VlcProc::CmdManage::execute()
00284 {
00285     // Just forward to VlcProc
00286     m_pParent->manage();
00287 }
00288 
00289 
00290 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
00291                            vlc_value_t oldVal, vlc_value_t newVal,
00292                            void *pParam )
00293 {
00294     VlcProc *pThis = (VlcProc*)pParam;
00295 
00296     // Update the stream variable
00297     playlist_t *p_playlist = (playlist_t*)pObj;
00298     pThis->updateStreamName(p_playlist);
00299 
00300     // Create a playlist notify command
00301     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
00302     // Create a playtree notify command
00303     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
00304 
00305     // Push the command in the asynchronous command queue
00306     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00307     pQueue->remove( "notify playlist" );
00308     pQueue->remove( "playtree changed" );
00309     pQueue->push( CmdGenericPtr( pCmd ) );
00310     pQueue->push( CmdGenericPtr( pCmdTree ) );
00311 
00312     return VLC_SUCCESS;
00313 }
00314 
00315 
00316 int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
00317                          vlc_value_t oldVal, vlc_value_t newVal,
00318                          void *pParam )
00319 {
00320     if (newVal.i_int)
00321     {
00322         VlcProc *pThis = (VlcProc*)pParam;
00323 
00324         // Create a raise all command
00325         CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
00326             pThis->getIntf()->p_sys->p_theme->getWindowManager() );
00327 
00328         // Push the command in the asynchronous command queue
00329         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00330         pQueue->remove( "raise all windows" );
00331         pQueue->push( CmdGenericPtr( pCmd ) );
00332     }
00333 
00334     return VLC_SUCCESS;
00335 }
00336 
00337 
00338 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
00339                            vlc_value_t oldVal, vlc_value_t newVal,
00340                            void *pParam )
00341 {
00342     VlcProc *pThis = (VlcProc*)pParam;
00343 
00344     // Update the stream variable
00345     playlist_t *p_playlist = (playlist_t*)pObj;
00346     pThis->updateStreamName(p_playlist);
00347 
00348     // Create a playlist notify command
00349     // TODO: selective update
00350     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
00351     // Create a playtree notify command
00352     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
00353                                                          newVal.i_int );
00354 
00355     // Push the command in the asynchronous command queue
00356     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00357     pQueue->remove( "notify playlist" );
00358     pQueue->remove( "playtree update" );
00359     pQueue->push( CmdGenericPtr( pCmd ) );
00360     pQueue->push( CmdGenericPtr( pCmdTree ) );
00361 
00362     return VLC_SUCCESS;
00363 }
00364 
00365 
00366 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
00367                                vlc_value_t oldVal, vlc_value_t newVal,
00368                                void *pParam )
00369 {
00370     VlcProc *pThis = (VlcProc*)pParam;
00371 
00372     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00373 
00374     // Update the stream variable
00375     playlist_t *p_playlist = (playlist_t*)pObj;
00376     pThis->updateStreamName(p_playlist);
00377 
00378     // Create a playlist notify command
00379     // TODO: selective update
00380     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
00381     // Create a playtree notify command
00382     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
00383 
00384     // Push the command in the asynchronous command queue
00385     pQueue->remove( "notify playlist" );
00386     pQueue->remove( "playtree changed" );
00387     pQueue->push( CmdGenericPtr( pCmd ) );
00388     pQueue->push( CmdGenericPtr( pCmdTree ) );
00389 
00390     return VLC_SUCCESS;
00391 }
00392 
00393 
00394 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
00395                            vlc_value_t oldVal, vlc_value_t newVal,
00396                            void *pParam )
00397 {
00398     VlcProc *pThis = (VlcProc*)pParam;
00399 
00400     // Create a playlist notify command
00401     CmdChangeSkin *pCmd =
00402         new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
00403 
00404     // Push the command in the asynchronous command queue
00405     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00406     pQueue->remove( "change skin" );
00407     pQueue->push( CmdGenericPtr( pCmd ) );
00408 
00409     return VLC_SUCCESS;
00410 }
00411 
00412 
00413 void VlcProc::updateStreamName( playlist_t *p_playlist )
00414 {
00415     if( p_playlist->p_input )
00416     {
00417         VarText &rStreamName = getStreamNameVar();
00418         VarText &rStreamURI = getStreamURIVar();
00419         // XXX: we should not need to access p_input->psz_source directly, a
00420         // getter should be provided by VLC core
00421         string name = p_playlist->p_input->input.p_item->psz_name;
00422         // XXX: This should be done in VLC core, not here...
00423         // Remove path information if any
00424         OSFactory *pFactory = OSFactory::instance( getIntf() );
00425         string::size_type pos = name.rfind( pFactory->getDirSeparator() );
00426         if( pos != string::npos )
00427         {
00428             name = name.substr( pos + 1, name.size() - pos + 1 );
00429         }
00430         UString srcName( getIntf(), name.c_str() );
00431         UString srcURI( getIntf(),
00432                          p_playlist->p_input->input.p_item->psz_uri );
00433 
00434         // Create commands to update the stream variables
00435         CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
00436         CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
00437         // Push the commands in the asynchronous command queue
00438         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
00439         pQueue->push( CmdGenericPtr( pCmd1 ) );
00440         pQueue->push( CmdGenericPtr( pCmd2 ) );
00441     }
00442 }
00443 
00444 
00445 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
00446                           int *pXHint, int *pYHint,
00447                           unsigned int *pWidthHint,
00448                           unsigned int *pHeightHint )
00449 {
00450     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
00451     pThis->m_pVout = pVout;
00452     if( pThis->m_handleSet.empty() )
00453     {
00454         return NULL;
00455     }
00456     else
00457     {
00458         // Get the window handle
00459         void *pWindow = *pThis->m_handleSet.begin();
00460         // Post a resize vout command
00461         CmdResizeVout *pCmd = new CmdResizeVout( pThis->getIntf(), pWindow,
00462                                                  *pWidthHint, *pHeightHint );
00463         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00464         pQueue->remove( "resize vout" );
00465         pQueue->push( CmdGenericPtr( pCmd ) );
00466         return pWindow;
00467     }
00468 }
00469 
00470 
00471 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
00472 {
00473     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
00474     pThis->m_pVout = NULL;
00475 }
00476 
00477 
00478 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
00479                             int query, va_list args )
00480 {
00481     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
00482 
00483     switch( query )
00484     {
00485         case VOUT_SET_ZOOM:
00486         {
00487             if( pThis->m_pVout )
00488             {
00489                 // Post a resize vout command
00490                 CmdResizeVout *pCmd =
00491                     new CmdResizeVout( pThis->getIntf(), pWindow,
00492                                        pThis->m_pVout->i_window_width,
00493                                        pThis->m_pVout->i_window_height );
00494                 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00495                 pQueue->remove( "resize vout" );
00496                 pQueue->push( CmdGenericPtr( pCmd ) );
00497             }
00498         }
00499 
00500         default:
00501             msg_Dbg( pIntf, "control query not supported" );
00502             break;
00503     }
00504 
00505     return VLC_SUCCESS;
00506 }
00507 

Generated on Tue Dec 20 10:14:43 2005 for vlc-0.8.4a by  doxygen 1.4.2