1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
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 *****************************************************************************/
28 #include "vlcproc.hpp"
29 #include "os_factory.hpp"
30 #include "os_timer.hpp"
31 #include "var_manager.hpp"
33 #include "window_manager.hpp"
34 #include "../commands/async_queue.hpp"
35 #include "../commands/cmd_change_skin.hpp"
36 #include "../commands/cmd_show_window.hpp"
37 #include "../commands/cmd_quit.hpp"
38 #include "../commands/cmd_vars.hpp"
39 #include "../utils/var_bool.hpp"
42 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
44 if( pIntf->p_sys->p_vlcProc == NULL )
46 pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
49 return pIntf->p_sys->p_vlcProc;
53 void VlcProc::destroy( intf_thread_t *pIntf )
55 if( pIntf->p_sys->p_vlcProc )
57 delete pIntf->p_sys->p_vlcProc;
58 pIntf->p_sys->p_vlcProc = NULL;
63 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
64 m_pVoutWindow( NULL ), m_pVout( NULL )
66 // Create a timer to poll the status of the vlc
67 OSFactory *pOsFactory = OSFactory::instance( pIntf );
68 m_pTimer = pOsFactory->createOSTimer( Callback( this, &doManage ) );
69 m_pTimer->start( 100, false );
71 // Create and register VLC variables
72 VarManager *pVarManager = VarManager::instance( getIntf() );
74 #define REGISTER_VAR( var, type, name ) \
75 var = VariablePtr( new type( getIntf() ) ); \
76 pVarManager->registerVar( var, name );
77 REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
78 pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
80 REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
81 REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
82 REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
83 REGISTER_VAR( m_cVarTime, StreamTime, "time" )
84 REGISTER_VAR( m_cVarVolume, Volume, "volume" )
85 REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
86 REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
87 REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
88 REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
89 REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
91 m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
92 pVarManager->registerVar( m_cVarStreamName, "streamName" );
93 m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
94 pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
97 // The object variable callbacks are called from other VLC threads,
98 // so they must put commands in the queue and NOT do anything else
99 // (X11 calls are not reentrant)
101 // Called when the playlist changes
102 var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
103 onIntfChange, this );
104 /* FIXME : properly handle item-append*/
105 var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
106 onIntfChange, this );
107 // Called when the "interface shower" wants us to show the skin
108 var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
110 // Called when the current played item changes
111 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
112 onPlaylistChange, this );
113 // Called when a playlist item changed
114 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
115 onItemChange, this );
116 // Called when our skins2 demux wants us to load a new skin
117 var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
119 // Callbacks for vout requests
120 getIntf()->pf_request_window = &getWindow;
121 getIntf()->pf_release_window = &releaseWindow;
122 getIntf()->pf_control_window = &controlWindow;
124 getIntf()->p_sys->p_input = NULL;
132 if( getIntf()->p_sys->p_input )
134 vlc_object_release( getIntf()->p_sys->p_input );
137 // Callbacks for vout requests
138 getIntf()->pf_request_window = NULL;
139 getIntf()->pf_release_window = NULL;
140 getIntf()->pf_control_window = NULL;
142 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
143 onIntfChange, this );
144 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
146 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
147 onPlaylistChange, this );
148 var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
149 onItemChange, this );
150 var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
154 void VlcProc::setVoutWindow( void *pVoutWindow )
156 m_pVoutWindow = pVoutWindow;
157 // Reparent the vout window
160 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
161 vout_Control( m_pVout, VOUT_CLOSE );
166 void VlcProc::dropVout()
170 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
171 vout_Control( m_pVout, VOUT_CLOSE );
177 void VlcProc::manage()
179 // Did the user requested to quit vlc ?
180 if( getIntf()->b_die || getIntf()->p_vlc->b_die )
182 CmdQuit *pCmd = new CmdQuit( getIntf() );
183 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
184 pQueue->push( CmdGenericPtr( pCmd ) );
187 // Get the VLC variables
188 StreamTime *pTime = (StreamTime*)m_cVarTime.get();
189 Volume *pVolume = (Volume*)m_cVarVolume.get();
190 VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
191 VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
192 VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
193 VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
194 VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
195 VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
196 VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
197 VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
199 // Refresh sound volume
200 audio_volume_t volume;
201 aout_VolumeGet( getIntf(), &volume );
202 pVolume->set( (double)volume / AOUT_VOLUME_MAX );
203 // Set the mute variable
204 pVarMute->set( volume == 0 );
207 if( getIntf()->p_sys->p_input == NULL )
209 getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
210 getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
212 else if( getIntf()->p_sys->p_input->b_dead )
214 vlc_object_release( getIntf()->p_sys->p_input );
215 getIntf()->p_sys->p_input = NULL;
218 input_thread_t *pInput = getIntf()->p_sys->p_input;
220 if( pInput && !pInput->b_die )
222 // Refresh time variables
224 var_Get( pInput, "position", &pos );
225 pTime->set( pos.f_float, false );
227 // Get the status of the playlist
228 playlist_status_t status =
229 getIntf()->p_sys->p_playlist->status.i_status;
231 pVarPlaying->set( status == PLAYLIST_RUNNING );
232 pVarStopped->set( status == PLAYLIST_STOPPED );
233 pVarPaused->set( status == PLAYLIST_PAUSED );
235 pVarSeekable->set( pos.f_float != 0.0 );
239 pVarPlaying->set( false );
240 pVarPaused->set( false );
241 pVarStopped->set( true );
242 pVarSeekable->set( false );
243 pTime->set( 0, false );
246 // Refresh the random variable
248 var_Get( getIntf()->p_sys->p_playlist, "random", &val );
249 pVarRandom->set( val.b_bool );
251 // Refresh the loop variable
252 var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
253 pVarLoop->set( val.b_bool );
255 // Refresh the repeat variable
256 var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
257 pVarRepeat->set( val.b_bool );
261 void VlcProc::doManage( SkinObject *pObj )
263 VlcProc *pThis = (VlcProc*)pObj;
268 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
269 vlc_value_t oldVal, vlc_value_t newVal,
272 VlcProc *pThis = (VlcProc*)pParam;
274 // Update the stream variable
275 playlist_t *p_playlist = (playlist_t*)pObj;
276 pThis->updateStreamName(p_playlist);
278 // Create a playlist notify command
279 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
281 // Push the command in the asynchronous command queue
282 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
283 pQueue->remove( "notify playlist" );
284 pQueue->push( CmdGenericPtr( pCmd ) );
290 int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
291 vlc_value_t oldVal, vlc_value_t newVal,
296 VlcProc *pThis = (VlcProc*)pParam;
298 // Create a raise all command
299 CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
300 pThis->getIntf()->p_sys->p_theme->getWindowManager() );
302 // Push the command in the asynchronous command queue
303 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
304 pQueue->remove( "raise all windows" );
305 pQueue->push( CmdGenericPtr( pCmd ) );
312 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
313 vlc_value_t oldVal, vlc_value_t newVal,
316 VlcProc *pThis = (VlcProc*)pParam;
318 // Update the stream variable
319 playlist_t *p_playlist = (playlist_t*)pObj;
320 pThis->updateStreamName(p_playlist);
322 // Create a playlist notify command
323 // TODO: selective update
324 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
326 // Push the command in the asynchronous command queue
327 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
328 pQueue->remove( "notify playlist" );
329 pQueue->push( CmdGenericPtr( pCmd ) );
335 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
336 vlc_value_t oldVal, vlc_value_t newVal,
339 VlcProc *pThis = (VlcProc*)pParam;
341 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
343 // Update the stream variable
344 playlist_t *p_playlist = (playlist_t*)pObj;
345 pThis->updateStreamName(p_playlist);
347 // Create a playlist notify command
348 // TODO: selective update
349 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
351 // Push the command in the asynchronous command queue
352 pQueue->remove( "notify playlist" );
353 pQueue->push( CmdGenericPtr( pCmd ) );
359 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
360 vlc_value_t oldVal, vlc_value_t newVal,
363 VlcProc *pThis = (VlcProc*)pParam;
365 // Create a playlist notify command
366 CmdChangeSkin *pCmd =
367 new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
369 // Push the command in the asynchronous command queue
370 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
371 pQueue->remove( "change skin" );
372 pQueue->push( CmdGenericPtr( pCmd ) );
378 void VlcProc::updateStreamName( playlist_t *p_playlist )
380 if( p_playlist->p_input )
382 VarText &rStreamName = getStreamNameVar();
383 VarText &rStreamURI = getStreamURIVar();
384 // XXX: we should not need to access p_input->psz_source directly, a
385 // getter should be provided by VLC core
387 string name = p_playlist->p_input->input.p_item->psz_name;
388 // XXX: This should be done in VLC core, not here...
389 // Remove path information if any
390 OSFactory *pFactory = OSFactory::instance( getIntf() );
391 string::size_type pos = name.rfind( pFactory->getDirSeparator() );
392 if( pos != string::npos )
394 name = name.substr( pos + 1, name.size() - pos + 1 );
396 UString srcName( getIntf(), name.c_str() );
397 UString srcURI( getIntf(),
398 p_playlist->p_input->input.p_item->psz_uri );
400 // Create commands to update the stream variables
401 CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
402 CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
403 // Push the commands in the asynchronous command queue
404 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
405 pQueue->push( CmdGenericPtr( pCmd1 ) );
406 pQueue->push( CmdGenericPtr( pCmd2 ) );
411 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
412 int *pXHint, int *pYHint,
413 unsigned int *pWidthHint,
414 unsigned int *pHeightHint )
416 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
417 pThis->m_pVout = pVout;
418 return pThis->m_pVoutWindow;
422 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
424 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
425 pThis->m_pVout = NULL;
429 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
430 int query, va_list args )