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_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
80 REGISTER_VAR( m_cVarTime, StreamTime, "time" )
81 REGISTER_VAR( m_cVarVolume, Volume, "volume" )
82 REGISTER_VAR( m_cVarStream, Stream, "stream" )
83 REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
84 REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
85 REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
86 REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
87 REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
91 // The object variable callbacks are called from other VLC threads,
92 // so they must put commands in the queue and NOT do anything else
93 // (X11 calls are not reentrant)
95 // Called when the playlist changes
96 var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
98 // Called when the current played item changes
99 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
100 onPlaylistChange, this );
101 // Called when a playlist item changed
102 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
103 onItemChange, this );
104 // Called when our skins2 demux wants us to load a new skin
105 var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
107 // Callbacks for vout requests
108 getIntf()->pf_request_window = &getWindow;
109 getIntf()->pf_release_window = &releaseWindow;
110 getIntf()->pf_control_window = &controlWindow;
112 getIntf()->p_sys->p_input = NULL;
120 if( getIntf()->p_sys->p_input )
122 vlc_object_release( getIntf()->p_sys->p_input );
125 // Callbacks for vout requests
126 getIntf()->pf_request_window = NULL;
127 getIntf()->pf_release_window = NULL;
128 getIntf()->pf_control_window = NULL;
130 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
131 onIntfChange, this );
132 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
133 onPlaylistChange, this );
134 var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
135 onItemChange, this );
139 void VlcProc::setVoutWindow( void *pVoutWindow )
141 m_pVoutWindow = pVoutWindow;
142 // Reparent the vout window
145 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
146 vout_Control( m_pVout, VOUT_CLOSE );
151 void VlcProc::manage()
153 // Did the user requested to quit vlc ?
154 if( getIntf()->b_die || getIntf()->p_vlc->b_die )
156 CmdQuit *pCmd = new CmdQuit( getIntf() );
157 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
158 pQueue->push( CmdGenericPtr( pCmd ) );
161 // Get the VLC variables
162 StreamTime *pTime = (StreamTime*)m_cVarTime.get();
163 Volume *pVolume = (Volume*)m_cVarVolume.get();
164 VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
165 VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
166 VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
167 VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
168 VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
169 VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
170 VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
171 VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
173 // Refresh sound volume
174 audio_volume_t volume;
175 aout_VolumeGet( getIntf(), &volume );
176 pVolume->set( (double)volume / AOUT_VOLUME_MAX );
177 // Set the mute variable
178 pVarMute->set( volume == 0 );
181 if( getIntf()->p_sys->p_input == NULL )
183 getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
184 getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
186 else if( getIntf()->p_sys->p_input->b_dead )
188 vlc_object_release( getIntf()->p_sys->p_input );
189 getIntf()->p_sys->p_input = NULL;
192 input_thread_t *pInput = getIntf()->p_sys->p_input;
194 if( pInput && !pInput->b_die )
196 // Refresh time variables
198 var_Get( pInput, "position", &pos );
199 pTime->set( pos.f_float, false );
201 // Get the status of the playlist
202 playlist_status_t status = getIntf()->p_sys->p_playlist->i_status;
204 pVarPlaying->set( status == PLAYLIST_RUNNING );
205 pVarStopped->set( status == PLAYLIST_STOPPED );
206 pVarPaused->set( status == PLAYLIST_PAUSED );
208 pVarSeekable->set( pos.f_float != 0.0 );
212 pVarPlaying->set( false );
213 pVarPaused->set( false );
214 pVarStopped->set( true );
215 pVarSeekable->set( false );
216 pTime->set( 0, false );
219 // Refresh the random variable
221 var_Get( getIntf()->p_sys->p_playlist, "random", &val );
222 pVarRandom->set( val.b_bool );
224 // Refresh the loop variable
225 var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
226 pVarLoop->set( val.b_bool );
228 // Refresh the repeat variable
229 var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
230 pVarRepeat->set( val.b_bool );
234 void VlcProc::doManage( SkinObject *pObj )
236 VlcProc *pThis = (VlcProc*)pObj;
241 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
242 vlc_value_t oldVal, vlc_value_t newVal,
245 VlcProc *pThis = ( VlcProc* )pParam;
247 // Create a playlist notify command
248 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
250 // Push the command in the asynchronous command queue
251 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
252 pQueue->remove( "notify playlist" );
253 pQueue->push( CmdGenericPtr( pCmd ) );
259 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
260 vlc_value_t oldVal, vlc_value_t newVal,
263 VlcProc *pThis = ( VlcProc* )pParam;
265 // Create a playlist notify command
266 // TODO: selective update
267 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
269 // Push the command in the asynchronous command queue
270 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
271 pQueue->remove( "notify playlist" );
272 pQueue->push( CmdGenericPtr( pCmd ) );
278 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
279 vlc_value_t oldVal, vlc_value_t newVal,
282 VlcProc *pThis = ( VlcProc* )pParam;
284 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
286 playlist_t *p_playlist = (playlist_t*)pObj;
287 if( p_playlist->p_input )
289 // Create a command to update the stream variable
290 // XXX: we should not need to access p_input->psz_source directly, a
291 // getter should be provided by VLC core
292 Stream *pStream = (Stream*)pThis->m_cVarStream.get();
294 UString srcName( pThis->getIntf(),
295 p_playlist->p_input->input.p_item->psz_uri );
296 CmdSetStream *pCmd = new CmdSetStream( pThis->getIntf(), *pStream,
298 // Push the command in the asynchronous command queue
299 pQueue->remove( "set stream" );
300 pQueue->push( CmdGenericPtr( pCmd ) );
303 // Create a playlist notify command
304 // TODO: selective update
305 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
307 // Push the command in the asynchronous command queue
308 pQueue->remove( "notify playlist" );
309 pQueue->push( CmdGenericPtr( pCmd ) );
315 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
316 vlc_value_t oldVal, vlc_value_t newVal,
319 VlcProc *pThis = ( VlcProc* )pParam;
321 // Create a playlist notify command
322 CmdChangeSkin *pCmd =
323 new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
325 // Push the command in the asynchronous command queue
326 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
327 pQueue->remove( "change skin" );
328 pQueue->push( CmdGenericPtr( pCmd ) );
334 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
335 int *pXHint, int *pYHint,
336 unsigned int *pWidthHint,
337 unsigned int *pHeightHint )
339 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
340 pThis->m_pVout = pVout;
341 return pThis->m_pVoutWindow;
345 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
347 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
348 pThis->m_pVout = NULL;
352 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
353 int query, va_list args )