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"
32 #include "../commands/async_queue.hpp"
33 #include "../commands/cmd_change_skin.hpp"
34 #include "../commands/cmd_quit.hpp"
35 #include "../commands/cmd_vars.hpp"
36 #include "../utils/var_bool.hpp"
39 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
41 if( pIntf->p_sys->p_vlcProc == NULL )
43 pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
46 return pIntf->p_sys->p_vlcProc;
50 void VlcProc::destroy( intf_thread_t *pIntf )
52 if( pIntf->p_sys->p_vlcProc )
54 delete pIntf->p_sys->p_vlcProc;
55 pIntf->p_sys->p_vlcProc = NULL;
60 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
61 m_pVoutWindow( NULL ), m_pVout( NULL )
63 // Create a timer to poll the status of the vlc
64 OSFactory *pOsFactory = OSFactory::instance( pIntf );
65 m_pTimer = pOsFactory->createOSTimer( Callback( this, &doManage ) );
66 m_pTimer->start( 100, false );
68 // Create and register VLC variables
69 VarManager *pVarManager = VarManager::instance( getIntf() );
71 #define REGISTER_VAR( var, type, name ) \
72 var = VariablePtr( new type( getIntf() ) ); \
73 pVarManager->registerVar( var, name );
74 REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
75 pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
77 REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
78 REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
79 REGISTER_VAR( m_cVarTime, StreamTime, "time" )
80 REGISTER_VAR( m_cVarVolume, Volume, "volume" )
81 REGISTER_VAR( m_cVarStream, Stream, "stream" )
82 REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
83 REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
84 REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
85 REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
86 REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
90 // The object variable callbacks are called from other VLC threads,
91 // so they must put commands in the queue and NOT do anything else
92 // (X11 calls are not reentrant)
94 // Called when the playlist changes
95 var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
97 // Called when the current played item changes
98 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
99 onPlaylistChange, this );
100 // Called when a playlist item changed
101 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
102 onItemChange, this );
103 // Called when our skins2 demux wants us to load a new skin
104 var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
106 // Callbacks for vout requests
107 getIntf()->pf_request_window = &getWindow;
108 getIntf()->pf_release_window = &releaseWindow;
109 getIntf()->pf_control_window = &controlWindow;
111 getIntf()->p_sys->p_input = NULL;
119 if( getIntf()->p_sys->p_input )
121 vlc_object_release( getIntf()->p_sys->p_input );
124 // Callbacks for vout requests
125 getIntf()->pf_request_window = NULL;
126 getIntf()->pf_release_window = NULL;
127 getIntf()->pf_control_window = NULL;
129 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
130 onIntfChange, this );
131 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
132 onPlaylistChange, this );
133 var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
134 onItemChange, this );
138 void VlcProc::setVoutWindow( void *pVoutWindow )
140 m_pVoutWindow = pVoutWindow;
141 // Reparent the vout window
144 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
145 vout_Control( m_pVout, VOUT_CLOSE );
150 void VlcProc::manage()
152 // Did the user requested to quit vlc ?
153 if( getIntf()->b_die || getIntf()->p_vlc->b_die )
155 CmdQuit *pCmd = new CmdQuit( getIntf() );
156 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
157 pQueue->push( CmdGenericPtr( pCmd ) );
160 // Get the VLC variables
161 StreamTime *pTime = (StreamTime*)m_cVarTime.get();
162 Volume *pVolume = (Volume*)m_cVarVolume.get();
163 VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
164 VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
165 VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
166 VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
167 VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
168 VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
169 VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
171 // Refresh sound volume
172 audio_volume_t volume;
173 aout_VolumeGet( getIntf(), &volume );
174 pVolume->set( (double)volume / AOUT_VOLUME_MAX );
175 // Set the mute variable
176 pVarMute->set( volume == 0 );
179 if( getIntf()->p_sys->p_input == NULL )
181 getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
182 getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
184 else if( getIntf()->p_sys->p_input->b_dead )
186 vlc_object_release( getIntf()->p_sys->p_input );
187 getIntf()->p_sys->p_input = NULL;
190 input_thread_t *pInput = getIntf()->p_sys->p_input;
192 if( pInput && !pInput->b_die )
194 // Refresh time variables
196 var_Get( pInput, "position", &pos );
197 pTime->set( pos.f_float, false );
199 // Get the status of the playlist
200 playlist_status_t status = getIntf()->p_sys->p_playlist->i_status;
202 pVarPlaying->set( status == PLAYLIST_RUNNING );
203 pVarStopped->set( status == PLAYLIST_STOPPED );
204 pVarPaused->set( status == PLAYLIST_PAUSED );
206 pVarSeekable->set( pos.f_float != 0.0 );
210 pVarPlaying->set( false );
211 pVarPaused->set( false );
212 pVarStopped->set( true );
213 pVarSeekable->set( false );
214 pTime->set( 0, false );
217 // Refresh the random variable
219 var_Get( getIntf()->p_sys->p_playlist, "random", &val );
220 pVarRandom->set( val.b_bool );
222 // Refresh the loop variable
223 var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
224 pVarLoop->set( val.b_bool );
228 void VlcProc::doManage( SkinObject *pObj )
230 VlcProc *pThis = (VlcProc*)pObj;
235 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
236 vlc_value_t oldVal, vlc_value_t newVal,
239 VlcProc *pThis = ( VlcProc* )pParam;
241 // Create a playlist notify command
242 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
244 // Push the command in the asynchronous command queue
245 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
246 pQueue->remove( "notify playlist" );
247 pQueue->push( CmdGenericPtr( pCmd ) );
253 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
254 vlc_value_t oldVal, vlc_value_t newVal,
257 VlcProc *pThis = ( VlcProc* )pParam;
259 // Create a playlist notify command
260 // TODO: selective update
261 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
263 // Push the command in the asynchronous command queue
264 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
265 pQueue->remove( "notify playlist" );
266 pQueue->push( CmdGenericPtr( pCmd ) );
272 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
273 vlc_value_t oldVal, vlc_value_t newVal,
276 VlcProc *pThis = ( VlcProc* )pParam;
278 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
280 playlist_t *p_playlist = (playlist_t*)pObj;
281 if( p_playlist->p_input )
283 // Create a command to update the stream variable
284 // XXX: we should not need to access p_input->psz_source directly, a
285 // getter should be provided by VLC core
286 Stream *pStream = (Stream*)pThis->m_cVarStream.get();
288 UString srcName( pThis->getIntf(),
289 p_playlist->p_input->input.p_item->psz_uri );
290 CmdSetStream *pCmd = new CmdSetStream( pThis->getIntf(), *pStream,
292 // Push the command in the asynchronous command queue
293 pQueue->remove( "set stream" );
294 pQueue->push( CmdGenericPtr( pCmd ) );
297 // Create a playlist notify command
298 // TODO: selective update
299 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
301 // Push the command in the asynchronous command queue
302 pQueue->remove( "notify playlist" );
303 pQueue->push( CmdGenericPtr( pCmd ) );
309 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
310 vlc_value_t oldVal, vlc_value_t newVal,
313 VlcProc *pThis = ( VlcProc* )pParam;
315 // Create a playlist notify command
316 CmdChangeSkin *pCmd =
317 new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
319 // Push the command in the asynchronous command queue
320 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
321 pQueue->remove( "change skin" );
322 pQueue->push( CmdGenericPtr( pCmd ) );
328 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
329 int *pXHint, int *pYHint,
330 unsigned int *pWidthHint,
331 unsigned int *pHeightHint )
333 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
334 pThis->m_pVout = pVout;
335 return pThis->m_pVoutWindow;
339 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
341 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
342 pThis->m_pVout = NULL;
346 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
347 int query, va_list args )