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_quit.hpp"
34 #include "../commands/cmd_vars.hpp"
35 #include "../utils/var_bool.hpp"
38 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
40 if( pIntf->p_sys->p_vlcProc == NULL )
42 pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
45 return pIntf->p_sys->p_vlcProc;
49 void VlcProc::destroy( intf_thread_t *pIntf )
51 if( pIntf->p_sys->p_vlcProc )
53 delete pIntf->p_sys->p_vlcProc;
54 pIntf->p_sys->p_vlcProc = NULL;
59 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
60 m_pVoutWindow( NULL ), m_pVout( NULL )
62 // Create a timer to poll the status of the vlc
63 OSFactory *pOsFactory = OSFactory::instance( pIntf );
64 m_pTimer = pOsFactory->createOSTimer( Callback( this, &doManage ) );
65 m_pTimer->start( 100, false );
67 // Create and register VLC variables
68 VarManager *pVarManager = VarManager::instance( getIntf() );
70 #define REGISTER_VAR( var, type, name ) \
71 var = VariablePtr( new type( getIntf() ) ); \
72 pVarManager->registerVar( var, name );
73 REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
74 pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
76 REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
77 REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
78 REGISTER_VAR( m_cVarTime, StreamTime, "time" )
79 REGISTER_VAR( m_cVarVolume, Volume, "volume" )
80 REGISTER_VAR( m_cVarStream, Stream, "stream" )
81 REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" ) // XXX broken
82 REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
83 REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
84 REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
85 REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
89 // The object variable callbacks are called from other VLC threads,
90 // so they must put commands in the queue and NOT do anything else
91 // (X11 calls are not reentrant)
93 // Called when the playlist changes
94 var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
96 // Called when the current played item changes
97 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
98 onPlaylistChange, this );
99 // Called when a playlist item changed
100 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
101 onItemChange, this );
103 // Callbacks for vout requests
104 getIntf()->pf_request_window = &getWindow;
105 getIntf()->pf_release_window = &releaseWindow;
106 getIntf()->pf_control_window = &controlWindow;
108 getIntf()->p_sys->p_input = NULL;
116 if( getIntf()->p_sys->p_input )
118 vlc_object_release( getIntf()->p_sys->p_input );
121 // Callbacks for vout requests
122 getIntf()->pf_request_window = NULL;
123 getIntf()->pf_release_window = NULL;
124 getIntf()->pf_control_window = NULL;
126 var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
127 onIntfChange, this );
128 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
129 onPlaylistChange, this );
130 var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
131 onItemChange, this );
135 void VlcProc::setVoutWindow( void *pVoutWindow )
137 m_pVoutWindow = pVoutWindow;
138 // Reparent the vout window
141 if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
142 vout_Control( m_pVout, VOUT_CLOSE );
147 void VlcProc::manage()
149 // Did the user requested to quit vlc ?
150 if( getIntf()->b_die || getIntf()->p_vlc->b_die )
152 CmdQuit *pCmd = new CmdQuit( getIntf() );
153 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
154 pQueue->push( CmdGenericPtr( pCmd ) );
157 // Get the VLC variables
158 StreamTime *pTime = (StreamTime*)m_cVarTime.get();
159 Volume *pVolume = (Volume*)m_cVarVolume.get();
160 VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
161 VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
162 VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
163 VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
164 VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
165 VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
166 VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
168 // Refresh sound volume
169 audio_volume_t volume;
170 aout_VolumeGet( getIntf(), &volume );
171 pVolume->set( (double)volume / AOUT_VOLUME_MAX );
172 // Set the mute variable
173 pVarMute->set( volume == 0 );
176 if( getIntf()->p_sys->p_input == NULL )
178 getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
179 getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
181 else if( getIntf()->p_sys->p_input->b_dead )
183 vlc_object_release( getIntf()->p_sys->p_input );
184 getIntf()->p_sys->p_input = NULL;
187 input_thread_t *pInput = getIntf()->p_sys->p_input;
189 if( pInput && !pInput->b_die )
191 // Refresh time variables
192 if( pInput->stream.b_seekable )
194 // Refresh position in the stream
196 var_Get( pInput, "position", &pos );
197 if( pos.f_float >= 0.0 )
199 pTime->set( pos.f_float, false );
204 pTime->set( 0, false );
207 // Get the status of the playlist
208 playlist_status_t status = getIntf()->p_sys->p_playlist->i_status;
210 pVarPlaying->set( status == PLAYLIST_RUNNING );
211 pVarStopped->set( status == PLAYLIST_STOPPED );
212 pVarPaused->set( status == PLAYLIST_PAUSED );
213 pVarSeekable->set( pInput->stream.b_seekable );
217 pVarPlaying->set( false );
218 pVarPaused->set( false );
219 pVarStopped->set( true );
220 pVarSeekable->set( false );
221 pTime->set( 0, false );
224 // Refresh the random variable
226 var_Get( getIntf()->p_sys->p_playlist, "random", &val );
227 pVarRandom->set( val.b_bool );
229 // Refresh the loop variable
230 var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
231 pVarLoop->set( val.b_bool );
235 void VlcProc::doManage( SkinObject *pObj )
237 VlcProc *pThis = (VlcProc*)pObj;
242 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
243 vlc_value_t oldVal, vlc_value_t newVal,
246 VlcProc *pThis = ( VlcProc* )pParam;
248 // Create a playlist notify command
249 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
251 // Push the command in the asynchronous command queue
252 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
253 pQueue->remove( "notify playlist" );
254 pQueue->push( CmdGenericPtr( pCmd ) );
260 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
261 vlc_value_t oldVal, vlc_value_t newVal,
264 VlcProc *pThis = ( VlcProc* )pParam;
266 // Create a playlist notify command
267 // TODO: selective update
268 CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
270 // Push the command in the asynchronous command queue
271 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
272 pQueue->remove( "notify playlist" );
273 pQueue->push( CmdGenericPtr( pCmd ) );
279 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
280 vlc_value_t oldVal, vlc_value_t newVal,
283 VlcProc *pThis = ( VlcProc* )pParam;
285 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
287 playlist_t *p_playlist = (playlist_t*)pObj;
288 if( p_playlist->p_input )
290 // Create a command to update the stream variable
291 // XXX: we should not need to access p_inpu->psz_source directly, a
292 // getter should be provided by VLC core
293 Stream *pStream = (Stream*)pThis->m_cVarStream.get();
294 UString srcName( pThis->getIntf(),
295 p_playlist->p_input->psz_source );
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 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
316 int *pXHint, int *pYHint,
317 unsigned int *pWidthHint,
318 unsigned int *pHeightHint )
320 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
321 pThis->m_pVout = pVout;
322 return pThis->m_pVoutWindow;
326 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
328 VlcProc *pThis = pIntf->p_sys->p_vlcProc;
329 pThis->m_pVout = NULL;
333 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
334 int query, va_list args )