00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00068 OSFactory *pOsFactory = OSFactory::instance( pIntf );
00069 m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
00070 m_pTimer->start( 100, false );
00071
00072
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
00104
00105
00106
00107
00108
00109 var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
00110 onIntfChange, this );
00111
00112
00113 var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
00114 onIntfChange, this );
00115
00116
00117 var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
00118 onIntfChange, this );
00119
00120 var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
00121 onIntfShow, this );
00122
00123 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
00124 onPlaylistChange, this );
00125
00126 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
00127 onItemChange, this );
00128
00129 var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
00130
00131
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
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
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
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
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
00222 audio_volume_t volume;
00223 aout_VolumeGet( getIntf(), &volume );
00224 pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX );
00225
00226 pVarMute->set( volume == 0 );
00227
00228
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
00245 vlc_value_t pos;
00246 var_Get( pInput, "position", &pos );
00247 pTime->set( pos.f_float, false );
00248
00249
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
00269 vlc_value_t val;
00270 var_Get( getIntf()->p_sys->p_playlist, "random", &val );
00271 pVarRandom->set( val.b_bool != 0 );
00272
00273
00274 var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
00275 pVarLoop->set( val.b_bool != 0 );
00276
00277
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
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
00297 playlist_t *p_playlist = (playlist_t*)pObj;
00298 pThis->updateStreamName(p_playlist);
00299
00300
00301 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
00302
00303 CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
00304
00305
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
00325 CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
00326 pThis->getIntf()->p_sys->p_theme->getWindowManager() );
00327
00328
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
00345 playlist_t *p_playlist = (playlist_t*)pObj;
00346 pThis->updateStreamName(p_playlist);
00347
00348
00349
00350 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
00351
00352 CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
00353 newVal.i_int );
00354
00355
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
00375 playlist_t *p_playlist = (playlist_t*)pObj;
00376 pThis->updateStreamName(p_playlist);
00377
00378
00379
00380 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
00381
00382 CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
00383
00384
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
00401 CmdChangeSkin *pCmd =
00402 new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
00403
00404
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
00420
00421 string name = p_playlist->p_input->input.p_item->psz_name;
00422
00423
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
00435 CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
00436 CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
00437
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
00459 void *pWindow = *pThis->m_handleSet.begin();
00460
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
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