vlcproc.cpp
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:13k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * vlcproc.cpp
  3.  *****************************************************************************
  4.  * Copyright (C) 2003 VideoLAN
  5.  * $Id: vlcproc.cpp 8966 2004-10-10 10:08:44Z ipkiss $
  6.  *
  7.  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  8.  *          Olivier Teuli鑢e <ipkiss@via.ecp.fr>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  23.  *****************************************************************************/
  24. #include <vlc/aout.h>
  25. #include <vlc/vout.h>
  26. #include "vlcproc.hpp"
  27. #include "os_factory.hpp"
  28. #include "os_timer.hpp"
  29. #include "var_manager.hpp"
  30. #include "theme.hpp"
  31. #include "window_manager.hpp"
  32. #include "../commands/async_queue.hpp"
  33. #include "../commands/cmd_change_skin.hpp"
  34. #include "../commands/cmd_show_window.hpp"
  35. #include "../commands/cmd_quit.hpp"
  36. #include "../commands/cmd_vars.hpp"
  37. #include "../utils/var_bool.hpp"
  38. VlcProc *VlcProc::instance( intf_thread_t *pIntf )
  39. {
  40.     if( pIntf->p_sys->p_vlcProc == NULL )
  41.     {
  42.         pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
  43.     }
  44.     return pIntf->p_sys->p_vlcProc;
  45. }
  46. void VlcProc::destroy( intf_thread_t *pIntf )
  47. {
  48.     if( pIntf->p_sys->p_vlcProc )
  49.     {
  50.         delete pIntf->p_sys->p_vlcProc;
  51.         pIntf->p_sys->p_vlcProc = NULL;
  52.     }
  53. }
  54. VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
  55.                   m_pVoutWindow( NULL ), m_pVout( NULL )
  56. {
  57.     // Create a timer to poll the status of the vlc
  58.     OSFactory *pOsFactory = OSFactory::instance( pIntf );
  59.     m_pTimer = pOsFactory->createOSTimer( Callback( this, &doManage ) );
  60.     m_pTimer->start( 100, false );
  61.     // Create and register VLC variables
  62.     VarManager *pVarManager = VarManager::instance( getIntf() );
  63. #define REGISTER_VAR( var, type, name ) 
  64.     var = VariablePtr( new type( getIntf() ) ); 
  65.     pVarManager->registerVar( var, name );
  66.     REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
  67.     pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
  68.                               "playlist.slider" );
  69.     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
  70.     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
  71.     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
  72.     REGISTER_VAR( m_cVarTime, StreamTime, "time" )
  73.     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
  74.     REGISTER_VAR( m_cVarStream, Stream, "stream" )
  75.     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
  76.     REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
  77.     REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
  78.     REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
  79.     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
  80. #undef REGISTER_VAR
  81.     // XXX WARNING XXX
  82.     // The object variable callbacks are called from other VLC threads,
  83.     // so they must put commands in the queue and NOT do anything else
  84.     // (X11 calls are not reentrant)
  85.     // Called when the playlist changes
  86.     var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
  87.                      onIntfChange, this );
  88.     // Called when the "interface shower" wants us to show the skin
  89.     var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
  90.                      onIntfShow, this );
  91.     // Called when the current played item changes
  92.     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
  93.                      onPlaylistChange, this );
  94.     // Called when a playlist item changed
  95.     var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
  96.                      onItemChange, this );
  97.     // Called when our skins2 demux wants us to load a new skin
  98.     var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
  99.     // Callbacks for vout requests
  100.     getIntf()->pf_request_window = &getWindow;
  101.     getIntf()->pf_release_window = &releaseWindow;
  102.     getIntf()->pf_control_window = &controlWindow;
  103.     getIntf()->p_sys->p_input = NULL;
  104. }
  105. VlcProc::~VlcProc()
  106. {
  107.     m_pTimer->stop();
  108.     delete( m_pTimer );
  109.     if( getIntf()->p_sys->p_input )
  110.     {
  111.         vlc_object_release( getIntf()->p_sys->p_input );
  112.     }
  113.     // Callbacks for vout requests
  114.     getIntf()->pf_request_window = NULL;
  115.     getIntf()->pf_release_window = NULL;
  116.     getIntf()->pf_control_window = NULL;
  117.     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
  118.                      onIntfChange, this );
  119.     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
  120.                      onIntfShow, this );
  121.     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
  122.                      onPlaylistChange, this );
  123.     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
  124.                      onItemChange, this );
  125.     var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
  126. }
  127. void VlcProc::setVoutWindow( void *pVoutWindow )
  128. {
  129.     m_pVoutWindow = pVoutWindow;
  130.     // Reparent the vout window
  131.     if( m_pVout )
  132.     {
  133.         if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
  134.             vout_Control( m_pVout, VOUT_CLOSE );
  135.     }
  136. }
  137. void VlcProc::manage()
  138. {
  139.     // Did the user requested to quit vlc ?
  140.     if( getIntf()->b_die || getIntf()->p_vlc->b_die )
  141.     {
  142.         CmdQuit *pCmd = new CmdQuit( getIntf() );
  143.         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
  144.         pQueue->push( CmdGenericPtr( pCmd ) );
  145.     }
  146.     // Get the VLC variables
  147.     StreamTime *pTime = (StreamTime*)m_cVarTime.get();
  148.     Volume *pVolume = (Volume*)m_cVarVolume.get();
  149.     VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
  150.     VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
  151.     VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
  152.     VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
  153.     VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
  154.     VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
  155.     VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
  156.     VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
  157.     // Refresh sound volume
  158.     audio_volume_t volume;
  159.     aout_VolumeGet( getIntf(), &volume );
  160.     pVolume->set( (double)volume / AOUT_VOLUME_MAX );
  161.     // Set the mute variable
  162.     pVarMute->set( volume == 0 );
  163.     // Update the input
  164.     if( getIntf()->p_sys->p_input == NULL )
  165.     {
  166.         getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
  167.             getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
  168.     }
  169.     else if( getIntf()->p_sys->p_input->b_dead )
  170.     {
  171.         vlc_object_release( getIntf()->p_sys->p_input );
  172.         getIntf()->p_sys->p_input = NULL;
  173.     }
  174.     input_thread_t *pInput = getIntf()->p_sys->p_input;
  175.     if( pInput && !pInput->b_die )
  176.     {
  177.         // Refresh time variables
  178.         vlc_value_t pos;
  179.         var_Get( pInput, "position", &pos );
  180.         pTime->set( pos.f_float, false );
  181.         // Get the status of the playlist
  182.         playlist_status_t status = getIntf()->p_sys->p_playlist->i_status;
  183.         pVarPlaying->set( status == PLAYLIST_RUNNING );
  184.         pVarStopped->set( status == PLAYLIST_STOPPED );
  185.         pVarPaused->set( status == PLAYLIST_PAUSED );
  186.         pVarSeekable->set( pos.f_float != 0.0 );
  187.     }
  188.     else
  189.     {
  190.         pVarPlaying->set( false );
  191.         pVarPaused->set( false );
  192.         pVarStopped->set( true );
  193.         pVarSeekable->set( false );
  194.         pTime->set( 0, false );
  195.     }
  196.     // Refresh the random variable
  197.     vlc_value_t val;
  198.     var_Get( getIntf()->p_sys->p_playlist, "random", &val );
  199.     pVarRandom->set( val.b_bool );
  200.     // Refresh the loop variable
  201.     var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
  202.     pVarLoop->set( val.b_bool );
  203.     // Refresh the repeat variable
  204.     var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
  205.     pVarRepeat->set( val.b_bool );
  206. }
  207. void VlcProc::doManage( SkinObject *pObj )
  208. {
  209.     VlcProc *pThis = (VlcProc*)pObj;
  210.     pThis->manage();
  211. }
  212. int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
  213.                            vlc_value_t oldVal, vlc_value_t newVal,
  214.                            void *pParam )
  215. {
  216.     VlcProc *pThis = (VlcProc*)pParam;
  217.     // Create a playlist notify command
  218.     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
  219.     // Push the command in the asynchronous command queue
  220.     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
  221.     pQueue->remove( "notify playlist" );
  222.     pQueue->push( CmdGenericPtr( pCmd ) );
  223.     return VLC_SUCCESS;
  224. }
  225. int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
  226.                          vlc_value_t oldVal, vlc_value_t newVal,
  227.                          void *pParam )
  228. {
  229.     if (newVal.i_int)
  230.     {
  231.         VlcProc *pThis = (VlcProc*)pParam;
  232.         // Create a raise all command
  233.         CmdRaiseAll *pCmd =
  234.             new CmdRaiseAll( pThis->getIntf(),
  235.                              pThis->getIntf()->p_sys->p_theme->getWindowManager() );
  236.         // Push the command in the asynchronous command queue
  237.         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
  238.         pQueue->remove( "raise all windows" );
  239.         pQueue->push( CmdGenericPtr( pCmd ) );
  240.     }
  241.     return VLC_SUCCESS;
  242. }
  243. int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
  244.                            vlc_value_t oldVal, vlc_value_t newVal,
  245.                            void *pParam )
  246. {
  247.     VlcProc *pThis = (VlcProc*)pParam;
  248.     // Create a playlist notify command
  249.     // TODO: selective update
  250.     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
  251.     // Push the command in the asynchronous command queue
  252.     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
  253.     pQueue->remove( "notify playlist" );
  254.     pQueue->push( CmdGenericPtr( pCmd ) );
  255.     return VLC_SUCCESS;
  256. }
  257. int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
  258.                                vlc_value_t oldVal, vlc_value_t newVal,
  259.                                void *pParam )
  260. {
  261.     VlcProc *pThis = (VlcProc*)pParam;
  262.     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
  263.     playlist_t *p_playlist = (playlist_t*)pObj;
  264.     if( p_playlist->p_input )
  265.     {
  266.         // Create a command to update the stream variable
  267.         // XXX: we should not need to access p_input->psz_source directly, a
  268.         // getter should be provided by VLC core
  269.         Stream *pStream = (Stream*)pThis->m_cVarStream.get();
  270. #warning "FIXME!"
  271.         UString srcName( pThis->getIntf(),
  272.                          p_playlist->p_input->input.p_item->psz_uri );
  273.         CmdSetStream *pCmd = new CmdSetStream( pThis->getIntf(), *pStream,
  274.                                                srcName, false );
  275.         // Push the command in the asynchronous command queue
  276.         pQueue->remove( "set stream" );
  277.         pQueue->push( CmdGenericPtr( pCmd ) );
  278.     }
  279.     // Create a playlist notify command
  280.     // TODO: selective update
  281.     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
  282.     // Push the command in the asynchronous command queue
  283.     pQueue->remove( "notify playlist" );
  284.     pQueue->push( CmdGenericPtr( pCmd ) );
  285.     return VLC_SUCCESS;
  286. }
  287. int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
  288.                            vlc_value_t oldVal, vlc_value_t newVal,
  289.                            void *pParam )
  290. {
  291.     VlcProc *pThis = (VlcProc*)pParam;
  292.     // Create a playlist notify command
  293.     CmdChangeSkin *pCmd =
  294.         new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
  295.     // Push the command in the asynchronous command queue
  296.     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
  297.     pQueue->remove( "change skin" );
  298.     pQueue->push( CmdGenericPtr( pCmd ) );
  299.     return VLC_SUCCESS;
  300. }
  301. void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
  302.                           int *pXHint, int *pYHint,
  303.                           unsigned int *pWidthHint,
  304.                           unsigned int *pHeightHint )
  305. {
  306.     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
  307.     pThis->m_pVout = pVout;
  308.     return pThis->m_pVoutWindow;
  309. }
  310. void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
  311. {
  312.     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
  313.     pThis->m_pVout = NULL;
  314. }
  315. int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
  316.                             int query, va_list args )
  317. {
  318.     return VLC_SUCCESS;
  319. }