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 // Called when a playlist item is added
105 // TODO: properly handle item-append
106 var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
107 onIntfChange, this );
108 // Called when a playlist item is deleted
109 // TODO: properly handle item-deleted
110 var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
111 onIntfChange, this );
112 // Called when the "interface shower" wants us to show the skin
113 var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
115 // Called when the current played item changes
116 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
117 onPlaylistChange, this );
118 // Called when a playlist item changed
119 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
120 onItemChange, this );
121 // Called when our skins2 demux wants us to load a new skin
122 var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
124 // Callbacks for vout requests
125 getIntf()->pf_request_window = &getWindow;
126 getIntf()->pf_release_window = &releaseWindow;
127 getIntf()->pf_control_window = &controlWindow;
129 getIntf()->p_sys->p_input = NULL;
137 if( getIntf()->p_sys->p_input )
139 vlc_object_release( getIntf()->p_sys->p_input );
142 // Callbacks for vout requests
143 getIntf()->pf_request_window = NULL;
144 getIntf()->pf_release_window = NULL;
145 getIntf()->pf_control_window = NULL;
147 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
148 onIntfChange, this );
149 var_DelCallback( getIntf()->p_sys->p_playlist, "item-append",
150 onIntfChange, this );
151 var_DelCallback( getIntf()->p_sys->p_playlist, "item-deleted",
152 onIntfChange, this );
153 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
155 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
156 onPlaylistChange, this );
157 var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
158 onItemChange, this );
159 var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
163 void VlcProc::setVoutWindow( void *pVoutWindow )
165 m_pVoutWindow = pVoutWindow;
166 // Reparent the vout window
169 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
170 vout_Control( m_pVout, VOUT_CLOSE );
175 void VlcProc::dropVout()
179 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
180 vout_Control( m_pVout, VOUT_CLOSE );
186 void VlcProc::manage()
188 // Did the user requested to quit vlc ?
189 if( getIntf()->b_die || getIntf()->p_vlc->b_die )
191 CmdQuit *pCmd = new CmdQuit( getIntf() );
192 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
193 pQueue->push( CmdGenericPtr( pCmd ) );
196 // Get the VLC variables
197 StreamTime *pTime = (StreamTime*)m_cVarTime.get();
198 Volume *pVolume = (Volume*)m_cVarVolume.get();
199 VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
200 VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
201 VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
202 VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
203 VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
204 VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
205 VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
206 VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
208 // Refresh sound volume
209 audio_volume_t volume;
210 aout_VolumeGet( getIntf(), &volume );
211 pVolume->set( (double)volume / AOUT_VOLUME_MAX );
212 // Set the mute variable
213 pVarMute->set( volume == 0 );
216 if( getIntf()->p_sys->p_input == NULL )
218 getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
219 getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
221 else if( getIntf()->p_sys->p_input->b_dead )
223 vlc_object_release( getIntf()->p_sys->p_input );
224 getIntf()->p_sys->p_input = NULL;
227 input_thread_t *pInput = getIntf()->p_sys->p_input;
229 if( pInput && !pInput->b_die )
231 // Refresh time variables
233 var_Get( pInput, "position", &pos );
234 pTime->set( pos.f_float, false );
236 // Get the status of the playlist
237 playlist_status_t status =
238 getIntf()->p_sys->p_playlist->status.i_status;
240 pVarPlaying->set( status == PLAYLIST_RUNNING );
241 pVarStopped->set( status == PLAYLIST_STOPPED );
242 pVarPaused->set( status == PLAYLIST_PAUSED );
244 pVarSeekable->set( pos.f_float != 0.0 );
248 pVarPlaying->set( false );
249 pVarPaused->set( false );
250 pVarStopped->set( true );
251 pVarSeekable->set( false );
252 pTime->set( 0, false );
255 // Refresh the random variable
257 var_Get( getIntf()->p_sys->p_playlist, "random", &val );
258 pVarRandom->set( val.b_bool );
260 // Refresh the loop variable
261 var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
262 pVarLoop->set( val.b_bool );
264 // Refresh the repeat variable
265 var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
266 pVarRepeat->set( val.b_bool );
270 void VlcProc::doManage( SkinObject *pObj )
272 VlcProc *pThis = (VlcProc*)pObj;
277 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
278 vlc_value_t oldVal, vlc_value_t newVal,
281 VlcProc *pThis = (VlcProc*)pParam;
283 // Update the stream variable
284 playlist_t *p_playlist = (playlist_t*)pObj;
285 pThis->updateStreamName(p_playlist);
287 // Create a playlist notify command
288 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
290 // Push the command in the asynchronous command queue
291 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
292 pQueue->remove( "notify playlist" );
293 pQueue->push( CmdGenericPtr( pCmd ) );
299 int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
300 vlc_value_t oldVal, vlc_value_t newVal,
305 VlcProc *pThis = (VlcProc*)pParam;
307 // Create a raise all command
308 CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
309 pThis->getIntf()->p_sys->p_theme->getWindowManager() );
311 // Push the command in the asynchronous command queue
312 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
313 pQueue->remove( "raise all windows" );
314 pQueue->push( CmdGenericPtr( pCmd ) );
321 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
322 vlc_value_t oldVal, vlc_value_t newVal,
325 VlcProc *pThis = (VlcProc*)pParam;
327 // Update the stream variable
328 playlist_t *p_playlist = (playlist_t*)pObj;
329 pThis->updateStreamName(p_playlist);
331 // Create a playlist notify command
332 // TODO: selective update
333 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
335 // Push the command in the asynchronous command queue
336 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
337 pQueue->remove( "notify playlist" );
338 pQueue->push( CmdGenericPtr( pCmd ) );
344 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
345 vlc_value_t oldVal, vlc_value_t newVal,
348 VlcProc *pThis = (VlcProc*)pParam;
350 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
352 // Update the stream variable
353 playlist_t *p_playlist = (playlist_t*)pObj;
354 pThis->updateStreamName(p_playlist);
356 // Create a playlist notify command
357 // TODO: selective update
358 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
360 // Push the command in the asynchronous command queue
361 pQueue->remove( "notify playlist" );
362 pQueue->push( CmdGenericPtr( pCmd ) );
368 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
369 vlc_value_t oldVal, vlc_value_t newVal,
372 VlcProc *pThis = (VlcProc*)pParam;
374 // Create a playlist notify command
375 CmdChangeSkin *pCmd =
376 new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
378 // Push the command in the asynchronous command queue
379 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
380 pQueue->remove( "change skin" );
381 pQueue->push( CmdGenericPtr( pCmd ) );
387 void VlcProc::updateStreamName( playlist_t *p_playlist )
389 if( p_playlist->p_input )
391 VarText &rStreamName = getStreamNameVar();
392 VarText &rStreamURI = getStreamURIVar();
393 // XXX: we should not need to access p_input->psz_source directly, a
394 // getter should be provided by VLC core
395 string name = p_playlist->p_input->input.p_item->psz_name;
396 // XXX: This should be done in VLC core, not here...
397 // Remove path information if any
398 OSFactory *pFactory = OSFactory::instance( getIntf() );
399 string::size_type pos = name.rfind( pFactory->getDirSeparator() );
400 if( pos != string::npos )
402 name = name.substr( pos + 1, name.size() - pos + 1 );
404 UString srcName( getIntf(), name.c_str() );
405 UString srcURI( getIntf(),
406 p_playlist->p_input->input.p_item->psz_uri );
408 // Create commands to update the stream variables
409 CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
410 CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
411 // Push the commands in the asynchronous command queue
412 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
413 pQueue->push( CmdGenericPtr( pCmd1 ) );
414 pQueue->push( CmdGenericPtr( pCmd2 ) );
419 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
420 int *pXHint, int *pYHint,
421 unsigned int *pWidthHint,
422 unsigned int *pHeightHint )
424 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
425 pThis->m_pVout = pVout;
426 return pThis->m_pVoutWindow;
430 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
432 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
433 pThis->m_pVout = NULL;
437 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
438 int query, va_list args )