]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
skins2: implement recording and next-frame
[vlc] / modules / gui / skins2 / src / vlcproc.cpp
1 /*****************************************************************************
2  * vlcproc.cpp
3  *****************************************************************************
4  * Copyright (C) 2003-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_aout.h>
31 #include <vlc_vout.h>
32 #include <vlc_playlist.h>
33
34 #include "vlcproc.hpp"
35 #include "os_factory.hpp"
36 #include "os_loop.hpp"
37 #include "os_timer.hpp"
38 #include "var_manager.hpp"
39 #include "vout_manager.hpp"
40 #include "theme.hpp"
41 #include "window_manager.hpp"
42 #include "../commands/async_queue.hpp"
43 #include "../commands/cmd_change_skin.hpp"
44 #include "../commands/cmd_show_window.hpp"
45 #include "../commands/cmd_quit.hpp"
46 #include "../commands/cmd_resize.hpp"
47 #include "../commands/cmd_vars.hpp"
48 #include "../commands/cmd_dialogs.hpp"
49 #include "../commands/cmd_update_item.hpp"
50 #include "../commands/cmd_audio.hpp"
51 #include "../commands/cmd_callbacks.hpp"
52 #include "../utils/var_bool.hpp"
53 #include <sstream>
54
55
56 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
57 {
58     if( pIntf->p_sys->p_vlcProc == NULL )
59     {
60         pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
61     }
62
63     return pIntf->p_sys->p_vlcProc;
64 }
65
66
67 void VlcProc::destroy( intf_thread_t *pIntf )
68 {
69     delete pIntf->p_sys->p_vlcProc;
70     pIntf->p_sys->p_vlcProc = NULL;
71 }
72
73
74 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
75     m_varVoutSize( pIntf ), m_varEqBands( pIntf ),
76     m_pVout( NULL ), m_pAout( NULL ), m_cmdManage( this )
77 {
78     // Create a timer to poll the status of the vlc
79     OSFactory *pOsFactory = OSFactory::instance( pIntf );
80     m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
81     m_pTimer->start( 100, false );
82
83     // Create and register VLC variables
84     VarManager *pVarManager = VarManager::instance( getIntf() );
85
86 #define REGISTER_VAR( var, type, name ) \
87     var = VariablePtr( new type( getIntf() ) ); \
88     pVarManager->registerVar( var, name );
89     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
90     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
91     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
92     REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
93     pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
94                               "playtree.slider" );
95     pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
96     pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
97
98     REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
99     REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
100     REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
101
102     /* Input variables */
103     pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
104     REGISTER_VAR( m_cVarTime, StreamTime, "time" )
105     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
106     REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
107
108     REGISTER_VAR( m_cVarRecordable, VarBoolImpl, "vlc.canRecord" )
109     REGISTER_VAR( m_cVarRecording, VarBoolImpl, "vlc.isRecording" )
110
111     /* Vout variables */
112     REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
113     REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
114
115     /* Aout variables */
116     REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
117     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
118     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
119     REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
120     REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
121
122 #undef REGISTER_VAR
123     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
124     pVarManager->registerVar( m_cVarStreamName, "streamName" );
125     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
126     pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
127     m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
128     pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
129     m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
130     pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
131
132     // Register the equalizer bands
133     for( int i = 0; i < EqualizerBands::kNbBands; i++)
134     {
135         stringstream ss;
136         ss << "equalizer.band(" << i << ")";
137         pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
138     }
139
140     // XXX WARNING XXX
141     // The object variable callbacks are called from other VLC threads,
142     // so they must put commands in the queue and NOT do anything else
143     // (X11 calls are not reentrant)
144
145     // Called when volume sound changes
146 #define ADD_CALLBACK( p_object, var ) \
147     var_AddCallback( p_object, var, onGenericCallback, this );
148
149     ADD_CALLBACK( pIntf->p_libvlc, "volume-change" )
150
151     ADD_CALLBACK( pIntf->p_sys->p_playlist, "item-current" )
152     ADD_CALLBACK( pIntf->p_sys->p_playlist, "random" )
153     ADD_CALLBACK( pIntf->p_sys->p_playlist, "loop" )
154     ADD_CALLBACK( pIntf->p_sys->p_playlist, "repeat" )
155
156 #undef ADD_CALLBACK
157
158     // Called when the playlist changes
159     var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
160                      onIntfChange, this );
161     // Called when a playlist item is added
162     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-append",
163                      onItemAppend, this );
164     // Called when a playlist item is deleted
165     // TODO: properly handle item-deleted
166     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-deleted",
167                      onItemDelete, this );
168     // Called when the "interface shower" wants us to show the skin
169     var_AddCallback( pIntf->p_libvlc, "intf-show",
170                      onIntfShow, this );
171     // Called when the current played item changes
172     var_AddCallback( pIntf->p_sys->p_playlist, "item-current",
173                      onPlaylistChange, this );
174     // Called when a playlist item changed
175     var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
176                      onItemChange, this );
177     // Called when our skins2 demux wants us to load a new skin
178     var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
179
180     // Called when we have an interaction dialog to display
181     var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
182     var_AddCallback( pIntf, "interaction", onInteraction, this );
183     interaction_Register( pIntf );
184
185     getIntf()->p_sys->p_input = NULL;
186 }
187
188
189 VlcProc::~VlcProc()
190 {
191     m_pTimer->stop();
192     delete( m_pTimer );
193
194     if( m_pAout )
195     {
196         vlc_object_release( m_pAout );
197         m_pAout = NULL;
198     }
199     if( m_pVout )
200     {
201         vlc_object_release( m_pVout );
202         m_pVout = NULL;
203     }
204
205     input_thread_t* pInput = getIntf()->p_sys->p_input;
206     if( pInput )
207     {
208         var_DelCallback( pInput, "intf-event", onGenericCallback, this );
209         var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
210         var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
211         var_DelCallback( pInput, "can-Record", onGenericCallback, this );
212
213         vlc_object_release( pInput );
214         getIntf()->p_sys->p_input = NULL;
215     }
216
217     interaction_Unregister( getIntf() );
218
219     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
220                      onIntfChange, this );
221     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
222                      onItemAppend, this );
223     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
224                      onItemDelete, this );
225     var_DelCallback( getIntf()->p_libvlc, "intf-show",
226                      onIntfShow, this );
227     var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
228                      onGenericCallback, this );
229     var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
230                      onPlaylistChange, this );
231     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
232                      onItemChange, this );
233     var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
234     var_DelCallback( getIntf(), "interaction", onInteraction, this );
235 }
236
237 void VlcProc::manage()
238 {
239     // Did the user request to quit vlc ?
240     if( !vlc_object_alive( getIntf() ) )
241     {
242         // Get the instance of OSFactory
243         OSFactory *pOsFactory = OSFactory::instance( getIntf() );
244
245         // Exit the main OS loop
246         pOsFactory->getOSLoop()->exit();
247
248         return;
249     }
250 }
251
252 void VlcProc::CmdManage::execute()
253 {
254     // Just forward to VlcProc
255     m_pParent->manage();
256 }
257
258
259 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
260                            vlc_value_t oldVal, vlc_value_t newVal,
261                            void *pParam )
262 {
263     VlcProc *pThis = (VlcProc*)pParam;
264
265     // Update the stream variable
266     pThis->updateStreamName();
267
268     // Create a playtree notify command (for new style playtree)
269     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
270
271     // Push the command in the asynchronous command queue
272     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
273     pQueue->push( CmdGenericPtr( pCmdTree ) );
274
275     return VLC_SUCCESS;
276 }
277
278
279 int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
280                          vlc_value_t oldVal, vlc_value_t newVal,
281                          void *pParam )
282 {
283     if (newVal.b_bool)
284     {
285         VlcProc *pThis = (VlcProc*)pParam;
286
287         // Create a raise all command
288         CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
289             pThis->getIntf()->p_sys->p_theme->getWindowManager() );
290
291         // Push the command in the asynchronous command queue
292         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
293         pQueue->push( CmdGenericPtr( pCmd ) );
294     }
295
296     return VLC_SUCCESS;
297 }
298
299
300 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
301                            vlc_value_t oldval, vlc_value_t newval,
302                            void *pParam )
303 {
304     VlcProc *pThis = (VlcProc*)pParam;
305     input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
306
307     // Update the stream variable
308     pThis->updateStreamName();
309
310     // Create a playtree notify command
311     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
312                                                          p_item->i_id );
313
314     // Push the command in the asynchronous command queue
315     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
316     pQueue->push( CmdGenericPtr( pCmdTree ), true );
317
318     return VLC_SUCCESS;
319 }
320
321 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
322                            vlc_value_t oldVal, vlc_value_t newVal,
323                            void *pParam )
324 {
325     VlcProc *pThis = (VlcProc*)pParam;
326
327     playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(
328                                                 playlist_add_t ) ) ;
329
330     memcpy( p_add, newVal.p_address, sizeof( playlist_add_t ) ) ;
331
332     CmdGenericPtr ptrTree;
333     CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
334                                                              p_add );
335     ptrTree = CmdGenericPtr( pCmdTree );
336
337     // Push the command in the asynchronous command queue
338     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
339     pQueue->push( ptrTree , false );
340
341     return VLC_SUCCESS;
342 }
343
344 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
345                            vlc_value_t oldVal, vlc_value_t newVal,
346                            void *pParam )
347 {
348     VlcProc *pThis = (VlcProc*)pParam;
349
350     int i_id = newVal.i_int;
351
352     CmdGenericPtr ptrTree;
353     CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
354                                                          i_id);
355     ptrTree = CmdGenericPtr( pCmdTree );
356
357     // Push the command in the asynchronous command queue
358     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
359     pQueue->push( ptrTree , false );
360
361     return VLC_SUCCESS;
362 }
363
364
365 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
366                                vlc_value_t oldval, vlc_value_t newval,
367                                void *pParam )
368 {
369     VlcProc *pThis = (VlcProc*)pParam;
370     input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
371
372     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
373
374     // Update the stream variable
375     pThis->updateStreamName();
376
377     // Create two playtree notify commands: one for old item, one for new
378 #if 0 /* FIXME: Heck, no! You cannot do that.
379          There is no warranty that the old item is still valid. */
380     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
381                                                          oldVal.i_int );
382     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
383 #endif
384     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), p_item->i_id );
385     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
386
387     return VLC_SUCCESS;
388 }
389
390
391 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
392                            vlc_value_t oldVal, vlc_value_t newVal,
393                            void *pParam )
394 {
395     VlcProc *pThis = (VlcProc*)pParam;
396
397     // Create a playlist notify command
398     CmdChangeSkin *pCmd =
399         new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
400
401     // Push the command in the asynchronous command queue
402     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
403     pQueue->push( CmdGenericPtr( pCmd ) );
404
405     return VLC_SUCCESS;
406 }
407
408 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
409                             vlc_value_t oldVal, vlc_value_t newVal,
410                             void *pParam )
411 {
412     VlcProc *pThis = (VlcProc*)pParam;
413     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
414
415     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
416     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
417     pQueue->push( CmdGenericPtr( pCmd ) );
418     return VLC_SUCCESS;
419 }
420
421
422 void VlcProc::updateStreamName()
423 {
424     // Create a update item command
425     CmdUpdateItem *pCmdItem = new CmdUpdateItem( getIntf(), getStreamNameVar(), getStreamURIVar() );
426
427     // Push the command in the asynchronous command queue
428     AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
429     pQueue->push( CmdGenericPtr( pCmdItem ) );
430 }
431
432 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
433                               vlc_value_t oldVal, vlc_value_t newVal,
434                               void *pParam )
435 {
436     VlcProc *pThis = (VlcProc*)pParam;
437
438     // Post a set equalizer bands command
439     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
440                                              pThis->m_varEqBands,
441                                              newVal.psz_string );
442     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
443     pQueue->push( CmdGenericPtr( pCmd ) );
444
445     return VLC_SUCCESS;
446 }
447
448
449 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
450                                vlc_value_t oldVal, vlc_value_t newVal,
451                                void *pParam )
452 {
453     VlcProc *pThis = (VlcProc*)pParam;
454     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
455
456     // Post a set preamp command
457     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
458                                               (newVal.f_float + 20.0) / 40.0 );
459     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
460     pQueue->push( CmdGenericPtr( pCmd ) );
461
462     return VLC_SUCCESS;
463 }
464
465
466 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
467                                 vlc_value_t oldVal, vlc_value_t newVal,
468                                 void *pParam )
469 {
470     VlcProc *pThis = (VlcProc*)pParam;
471     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
472
473     CmdGeneric *pCmd = NULL;
474
475 #define ADD_CALLBACK_ENTRY( var, label ) \
476     { \
477     if( strcmp( pVariable, var ) == 0 ) \
478         pCmd = new Cmd_##label( pThis->getIntf(), pObj, newVal ); \
479     }
480
481     ADD_CALLBACK_ENTRY( "item-current", item_current_changed )
482     ADD_CALLBACK_ENTRY( "volume-change", volume_changed )
483
484     ADD_CALLBACK_ENTRY( "intf-event", intf_event_changed )
485     ADD_CALLBACK_ENTRY( "bit-rate", bit_rate_changed )
486     ADD_CALLBACK_ENTRY( "sample-rate", sample_rate_changed )
487     ADD_CALLBACK_ENTRY( "can-record", can_record_changed )
488
489     ADD_CALLBACK_ENTRY( "random", random_changed )
490     ADD_CALLBACK_ENTRY( "loop", loop_changed )
491     ADD_CALLBACK_ENTRY( "repeat", repeat_changed )
492
493     ADD_CALLBACK_ENTRY( "audio-filter", audio_filter_changed )
494
495 #undef ADD_CALLBACK_ENTRY
496
497     if( pCmd )
498         pQueue->push( CmdGenericPtr( pCmd ), false );
499     else
500         msg_Err( pObj, "no Callback entry provided for %s", pVariable );
501
502     return VLC_SUCCESS;
503 }
504
505 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
506 {
507     input_thread_t* pInput = getIntf()->p_sys->p_input;
508     if( pInput )
509     {
510         var_DelCallback( pInput, "intf-event", onGenericCallback, this );
511         var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
512         var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
513         var_DelCallback( pInput, "can-record", onGenericCallback, this );
514         vlc_object_release( pInput );
515         pInput = getIntf()->p_sys->p_input = NULL;
516     }
517
518     playlist_t * pPlaylist = getIntf()->p_sys->p_playlist;
519     pInput = playlist_CurrentInput( pPlaylist );
520     if( !pInput )
521         return;
522
523     var_AddCallback( pInput, "intf-event", onGenericCallback, this );
524     var_AddCallback( pInput, "bit-rate", onGenericCallback, this );
525     var_AddCallback( pInput, "sample-rate", onGenericCallback, this );
526     var_AddCallback( pInput, "can-record", onGenericCallback, this );
527     getIntf()->p_sys->p_input = pInput;
528 }
529
530 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
531 {
532     input_thread_t* pInput = (input_thread_t*) p_obj;
533
534     StreamTime *pTime = (StreamTime*)m_cVarTime.get();
535     VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
536     VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
537     VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
538     VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get();
539     VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
540     VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
541     VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
542     VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
543     VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
544
545     if( vlc_object_alive( pInput ) )
546     {
547         switch( newVal.i_int )
548         {
549             case INPUT_EVENT_STATE:
550             {
551                 int state = var_GetInteger( pInput, "state" );
552                 pVarStopped->set( false );
553                 pVarPlaying->set( state != PAUSE_S );
554                 pVarPaused->set( state == PAUSE_S );
555                 break;
556             }
557
558             case INPUT_EVENT_POSITION:
559             {
560                 float pos = var_GetFloat( pInput, "position" );
561                 pTime->set( pos, false );
562                 pVarSeekable->set( pos != 0.0 );
563                 break;
564             }
565
566             case INPUT_EVENT_ES:
567             {
568                 // Do we have audio
569                 vlc_value_t audio_es;
570                 var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
571                                 &audio_es, NULL );
572                 pVarHasAudio->set( audio_es.i_int > 0 );
573                 break;
574             }
575
576             case INPUT_EVENT_VOUT:
577             {
578                 vout_thread_t* pVout = input_GetVout( pInput );
579                 pVarHasVout->set( pVout != NULL );
580                 if( pVout )
581                 {
582                     pVarFullscreen->set( var_GetBool( pVout, "fullscreen" ) );
583                     vlc_object_release( pVout );
584                 }
585                 break;
586             }
587
588             case INPUT_EVENT_AOUT:
589             {
590                 char *pFilters;
591                 aout_instance_t* pAout = input_GetAout( pInput );
592                 if( pAout )
593                 {
594                     if( m_pAout )
595                     {
596                         var_DelCallback( m_pAout, "audio-filter",
597                                          onGenericCallback, this );
598                         var_DelCallback( m_pAout, "equalizer-bands",
599                                          onEqBandsChange, this );
600                         var_DelCallback( m_pAout, "equalizer-preamp",
601                                          onEqPreampChange, this );
602                         vlc_object_release( m_pAout );
603                         m_pAout = NULL;
604                     }
605
606                     var_AddCallback( pAout, "audio-filter",
607                                      onGenericCallback, this );
608                     var_AddCallback( pAout, "equalizer-bands",
609                                   onEqBandsChange, this );
610                     var_AddCallback( pAout, "equalizer-preamp",
611                                   onEqPreampChange, this );
612                     m_pAout = pAout;
613
614                     pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
615                 }
616                 else
617                 {
618                     if( m_pAout )
619                     {
620                         var_DelCallback( m_pAout, "audio-filter",
621                                          onGenericCallback, this );
622                         var_DelCallback( m_pAout, "equalizer-bands",
623                                          onEqBandsChange, this );
624                         var_DelCallback( m_pAout, "equalizer-preamp",
625                                          onEqPreampChange, this );
626                         vlc_object_release( m_pAout );
627                         m_pAout = NULL;
628                     }
629                     // Get the audio filters
630                     pFilters = config_GetPsz( getIntf(), "audio-filter" );
631                 }
632                 // Refresh the equalizer variable
633                 bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
634                 pVarEqualizer->set( b_equalizer );
635                 free( pFilters );
636                 break;
637             }
638
639             case INPUT_EVENT_CHAPTER:
640             {
641                 vlc_value_t chapters_count;
642                 var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
643                             &chapters_count, NULL );
644                 pVarDvdActive->set( chapters_count.i_int > 0 );
645                 break;
646             }
647
648             case INPUT_EVENT_RECORD:
649             {
650                 VarBoolImpl *pVarRecording =
651                                (VarBoolImpl*)m_cVarRecording.get();
652                 pVarRecording->set( var_GetBool( pInput, "record" ) );
653                 break;
654             }
655
656             INPUT_EVENT_DEAD:
657             INPUT_EVENT_ABORT:
658             {
659                 var_DelCallback( pInput, "intf-event",
660                                           onGenericCallback, this );
661                 var_DelCallback( pInput, "bit-rate",
662                                           onGenericCallback, this );
663                 var_DelCallback( pInput, "sample-rate",
664                                           onGenericCallback, this );
665                 var_DelCallback( pInput, "can-record" ,
666                                           onGenericCallback, this );
667                 vlc_object_release( pInput );
668                 getIntf()->p_sys->p_input = NULL;
669                 break;
670             }
671
672             default:
673                 break;
674         }
675     }
676     else
677     {
678         // pVarSeekable->set( false );
679         pVarDvdActive->set( false );
680         pTime->set( 0, false );
681         pVarFullscreen->set( false );
682         pVarHasAudio->set( false );
683         pVarHasVout->set( false );
684         pVarStopped->set( true );
685         pVarPlaying->set( false );
686         pVarPaused->set( false );
687     }
688 }
689
690 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
691 {
692     input_thread_t* pInput = (input_thread_t*) p_obj;
693
694     VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get();
695
696     int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
697     pBitrate->set( UString::fromInt( getIntf(), bitrate ) );
698 }
699
700 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
701 {
702     input_thread_t* pInput = (input_thread_t*) p_obj;
703
704     VarText *pSampleRate = (VarText*)m_cVarStreamSampleRate.get();
705
706     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
707     pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );
708 }
709
710 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
711 {
712     input_thread_t* pInput = (input_thread_t*) p_obj;
713
714     VarBoolImpl *pVarRecordable = (VarBoolImpl*)m_cVarRecordable.get();
715     pVarRecordable->set( var_GetBool(  pInput, "can-record" ) );
716 }
717
718 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
719 {
720     playlist_t* pPlaylist = (playlist_t*) p_obj;
721
722     // Refresh the random variable
723     VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
724     pVarRandom->set( var_GetBool( pPlaylist, "random" ) );
725 }
726
727 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
728 {
729     playlist_t* pPlaylist = (playlist_t*) p_obj;
730
731     // Refresh the loop variable
732     VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
733     pVarLoop->set( var_GetBool( pPlaylist, "loop" ) );
734 }
735
736 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
737 {
738     playlist_t* pPlaylist = (playlist_t*) p_obj;
739
740     // Refresh the repeat variable
741     VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
742     pVarRepeat->set( var_GetBool( pPlaylist, "repeat" ) );
743 }
744
745
746 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
747 {
748     (void)p_obj; (void)newVal;
749     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
750
751     // Refresh sound volume
752     audio_volume_t volume;
753     aout_VolumeGet( pPlaylist, &volume );
754     Volume *pVolume = (Volume*)m_cVarVolume.get();
755     pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX, false );
756
757     // Set the mute variable
758     VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
759     pVarMute->set( volume == 0 );
760 }
761
762 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
763 {
764     aout_instance_t* pAout = (aout_instance_t*) p_obj;
765
766     char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
767
768     VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
769
770     // Refresh the equalizer variable
771     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
772     pVarEqualizer->set( b_equalizer );
773     free( pFilters );
774 }