]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
02519e945699f46b0ac00cdea8a48ceeea0bfe9d
[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  *          Erwan Tulou      <erwan10@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <vlc_common.h>
31 #include <vlc_aout.h>
32 #include <vlc_vout.h>
33 #include <vlc_playlist.h>
34 #include <vlc_url.h>
35
36 #include "vlcproc.hpp"
37 #include "os_factory.hpp"
38 #include "os_loop.hpp"
39 #include "os_timer.hpp"
40 #include "var_manager.hpp"
41 #include "vout_manager.hpp"
42 #include "fsc_window.hpp"
43 #include "theme.hpp"
44 #include "window_manager.hpp"
45 #include "../commands/async_queue.hpp"
46 #include "../commands/cmd_change_skin.hpp"
47 #include "../commands/cmd_show_window.hpp"
48 #include "../commands/cmd_quit.hpp"
49 #include "../commands/cmd_resize.hpp"
50 #include "../commands/cmd_vars.hpp"
51 #include "../commands/cmd_dialogs.hpp"
52 #include "../commands/cmd_audio.hpp"
53 #include "../commands/cmd_callbacks.hpp"
54 #include "../utils/var_bool.hpp"
55 #include "../utils/var_string.hpp"
56 #include <sstream>
57
58 #include <assert.h>
59
60 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
61 {
62     if( pIntf->p_sys->p_vlcProc == NULL )
63     {
64         pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
65     }
66
67     return pIntf->p_sys->p_vlcProc;
68 }
69
70
71 void VlcProc::destroy( intf_thread_t *pIntf )
72 {
73     delete pIntf->p_sys->p_vlcProc;
74     pIntf->p_sys->p_vlcProc = NULL;
75 }
76
77
78 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
79     m_varEqBands( pIntf ), m_pVout( NULL ), m_pAout( NULL ),
80     m_bEqualizer_started( false ), m_cmdManage( this )
81 {
82     // Create a timer to poll the status of the vlc
83     OSFactory *pOsFactory = OSFactory::instance( pIntf );
84     m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
85     m_pTimer->start( 100, false );
86
87     // Create and register VLC variables
88     VarManager *pVarManager = VarManager::instance( getIntf() );
89
90 #define REGISTER_VAR( var, type, name ) \
91     var = VariablePtr( new type( getIntf() ) ); \
92     pVarManager->registerVar( var, name );
93     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
94     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
95     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
96     REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
97     pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
98                               "playtree.slider" );
99     pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
100     pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
101
102     REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
103     REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
104     REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
105
106     /* Input variables */
107     pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
108     REGISTER_VAR( m_cVarTime, StreamTime, "time" )
109     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
110     REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
111
112     REGISTER_VAR( m_cVarRecordable, VarBoolImpl, "vlc.canRecord" )
113     REGISTER_VAR( m_cVarRecording, VarBoolImpl, "vlc.isRecording" )
114
115     /* Vout variables */
116     REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
117     REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
118
119     /* Aout variables */
120     REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
121     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
122     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
123     REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
124     REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
125
126 #undef REGISTER_VAR
127     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
128     pVarManager->registerVar( m_cVarStreamName, "streamName" );
129     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
130     pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
131     m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
132     pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
133     m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
134     pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
135     m_cVarStreamArt = VariablePtr( new VarString( getIntf() ) );
136     pVarManager->registerVar( m_cVarStreamArt, "streamArt" );
137
138     // Register the equalizer bands
139     for( int i = 0; i < EqualizerBands::kNbBands; i++)
140     {
141         stringstream ss;
142         ss << "equalizer.band(" << i << ")";
143         pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
144     }
145
146     // XXX WARNING XXX
147     // The object variable callbacks are called from other VLC threads,
148     // so they must put commands in the queue and NOT do anything else
149     // (X11 calls are not reentrant)
150
151 #define ADD_CALLBACK( p_object, var ) \
152     var_AddCallback( p_object, var, onGenericCallback, this );
153
154     ADD_CALLBACK( pIntf->p_sys->p_playlist, "volume-change" )
155     ADD_CALLBACK( pIntf->p_libvlc, "intf-show" )
156
157     ADD_CALLBACK( pIntf->p_sys->p_playlist, "item-current" )
158     ADD_CALLBACK( pIntf->p_sys->p_playlist, "random" )
159     ADD_CALLBACK( pIntf->p_sys->p_playlist, "loop" )
160     ADD_CALLBACK( pIntf->p_sys->p_playlist, "repeat" )
161
162 #undef ADD_CALLBACK
163
164     // Called when a playlist item is added
165     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-append",
166                      onItemAppend, this );
167     // Called when a playlist item is deleted
168     // TODO: properly handle item-deleted
169     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-deleted",
170                      onItemDelete, this );
171     // Called when the current input changes
172     var_AddCallback( pIntf->p_sys->p_playlist, "input-current",
173                      onInputNew, this );
174     // Called when a playlist item changed
175     var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
176                      onItemChange, this );
177
178     // Called when we have an interaction dialog to display
179     var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
180     var_AddCallback( pIntf, "interaction", onInteraction, this );
181     interaction_Register( pIntf );
182
183     // initialize variables refering to liblvc and playlist objects
184     init_variables();
185 }
186
187
188 VlcProc::~VlcProc()
189 {
190     m_pTimer->stop();
191     delete( m_pTimer );
192
193     if( m_pAout )
194     {
195         vlc_object_release( m_pAout );
196         m_pAout = NULL;
197     }
198     if( m_pVout )
199     {
200         vlc_object_release( m_pVout );
201         m_pVout = NULL;
202     }
203
204     interaction_Unregister( getIntf() );
205
206     var_DelCallback( getIntf()->p_sys->p_playlist, "volume-change",
207                      onGenericCallback, this );
208     var_DelCallback( getIntf()->p_libvlc, "intf-show",
209                      onGenericCallback, this );
210
211     var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
212                      onGenericCallback, this );
213     var_DelCallback( getIntf()->p_sys->p_playlist, "random",
214                      onGenericCallback, this );
215     var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
216                      onGenericCallback, this );
217     var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
218                      onGenericCallback, this );
219
220     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
221                      onItemAppend, this );
222     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
223                      onItemDelete, this );
224     var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
225                      onInputNew, this );
226     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
227                      onItemChange, this );
228     var_DelCallback( getIntf(), "interaction", onInteraction, this );
229 }
230
231 void VlcProc::manage()
232 {
233     // Did the user request to quit vlc ?
234     if( !vlc_object_alive( getIntf() ) )
235     {
236         // Get the instance of OSFactory
237         OSFactory *pOsFactory = OSFactory::instance( getIntf() );
238
239         // Exit the main OS loop
240         pOsFactory->getOSLoop()->exit();
241
242         return;
243     }
244 }
245
246 void VlcProc::CmdManage::execute()
247 {
248     // Just forward to VlcProc
249     m_pParent->manage();
250 }
251
252
253 int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
254                          vlc_value_t oldval, vlc_value_t newval, void *pParam )
255 {
256     VlcProc *pThis = (VlcProc*)pParam;
257     input_thread_t *pInput = static_cast<input_thread_t*>(newval.p_address);
258
259     var_AddCallback( pInput, "intf-event", onGenericCallback2, pThis );
260     var_AddCallback( pInput, "bit-rate", onGenericCallback, pThis );
261     var_AddCallback( pInput, "sample-rate", onGenericCallback, pThis );
262     var_AddCallback( pInput, "can-record", onGenericCallback, pThis );
263
264     return VLC_SUCCESS;
265 }
266
267
268 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
269                            vlc_value_t oldval, vlc_value_t newval,
270                            void *pParam )
271 {
272     VlcProc *pThis = (VlcProc*)pParam;
273     input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
274
275     // Create a playtree notify command
276     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
277                                                          p_item );
278
279     // Push the command in the asynchronous command queue
280     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
281     pQueue->push( CmdGenericPtr( pCmdTree ), true );
282
283     return VLC_SUCCESS;
284 }
285
286 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
287                            vlc_value_t oldVal, vlc_value_t newVal,
288                            void *pParam )
289 {
290     VlcProc *pThis = (VlcProc*)pParam;
291
292     playlist_add_t *p_add = static_cast<playlist_add_t*>(newVal.p_address);
293     CmdPlaytreeAppend *pCmdTree =
294         new CmdPlaytreeAppend( pThis->getIntf(), p_add );
295
296     // Push the command in the asynchronous command queue
297     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
298     pQueue->push( CmdGenericPtr( pCmdTree ), false );
299
300     return VLC_SUCCESS;
301 }
302
303 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
304                            vlc_value_t oldVal, vlc_value_t newVal,
305                            void *pParam )
306 {
307     VlcProc *pThis = (VlcProc*)pParam;
308
309     int i_id = newVal.i_int;
310     CmdPlaytreeDelete *pCmdTree =
311         new CmdPlaytreeDelete( pThis->getIntf(), i_id);
312
313     // Push the command in the asynchronous command queue
314     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
315     pQueue->push( CmdGenericPtr( pCmdTree ), false );
316
317     return VLC_SUCCESS;
318 }
319
320 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
321                             vlc_value_t oldVal, vlc_value_t newVal,
322                             void *pParam )
323 {
324     VlcProc *pThis = (VlcProc*)pParam;
325     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
326
327     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
328     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
329     pQueue->push( CmdGenericPtr( pCmd ) );
330     return VLC_SUCCESS;
331 }
332
333 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
334                               vlc_value_t oldVal, vlc_value_t newVal,
335                               void *pParam )
336 {
337     VlcProc *pThis = (VlcProc*)pParam;
338
339     // Post a set equalizer bands command
340     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
341                                              pThis->m_varEqBands,
342                                              newVal.psz_string );
343     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
344     pQueue->push( CmdGenericPtr( pCmd ) );
345
346     return VLC_SUCCESS;
347 }
348
349
350 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
351                                vlc_value_t oldVal, vlc_value_t newVal,
352                                void *pParam )
353 {
354     VlcProc *pThis = (VlcProc*)pParam;
355     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
356
357     // Post a set preamp command
358     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
359                                               (newVal.f_float + 20.0) / 40.0 );
360     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
361     pQueue->push( CmdGenericPtr( pCmd ) );
362
363     return VLC_SUCCESS;
364 }
365
366
367 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
368                                 vlc_value_t oldVal, vlc_value_t newVal,
369                                 void *pParam )
370 {
371     VlcProc *pThis = (VlcProc*)pParam;
372     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
373
374 #define ADD_CALLBACK_ENTRY( var, func, remove ) \
375     { \
376     if( strcmp( pVariable, var ) == 0 ) \
377     { \
378         string label = var; \
379         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal, \
380                                             &VlcProc::func, label ); \
381         if( pCmd ) \
382             pQueue->push( CmdGenericPtr( pCmd ), remove ); \
383         return VLC_SUCCESS; \
384     } \
385     }
386
387     ADD_CALLBACK_ENTRY( "item-current", on_item_current_changed, false )
388     ADD_CALLBACK_ENTRY( "volume-change", on_volume_changed, true )
389
390     ADD_CALLBACK_ENTRY( "bit-rate", on_bit_rate_changed, false )
391     ADD_CALLBACK_ENTRY( "sample-rate", on_sample_rate_changed, false )
392     ADD_CALLBACK_ENTRY( "can-record", on_can_record_changed, false )
393
394     ADD_CALLBACK_ENTRY( "random", on_random_changed, false )
395     ADD_CALLBACK_ENTRY( "loop", on_loop_changed, false )
396     ADD_CALLBACK_ENTRY( "repeat", on_repeat_changed, false )
397
398     ADD_CALLBACK_ENTRY( "audio-filter", on_audio_filter_changed, false )
399
400     ADD_CALLBACK_ENTRY( "intf-show", on_intf_show_changed, false )
401
402     ADD_CALLBACK_ENTRY( "mouse-moved", on_mouse_moved_changed, false )
403
404 #undef ADD_CALLBACK_ENTRY
405
406     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
407     return VLC_EGENERIC;
408 }
409
410
411 int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable,
412                                  vlc_value_t oldVal, vlc_value_t newVal,
413                                  void *pParam )
414 {
415     VlcProc *pThis = (VlcProc*)pParam;
416     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
417
418     /**
419      * For intf-event, commands are labeled based on the value of newVal.
420      *
421      * For some values (e.g position), only keep the latest command
422      * when there are multiple pending commands (remove=true).
423      *
424      * for others, don't discard commands (remove=false)
425      **/
426     if( strcmp( pVariable, "intf-event" ) == 0 )
427     {
428         stringstream label;
429         bool b_remove;
430         switch( newVal.i_int )
431         {
432             case INPUT_EVENT_STATE:
433             case INPUT_EVENT_POSITION:
434             case INPUT_EVENT_ES:
435             case INPUT_EVENT_CHAPTER:
436             case INPUT_EVENT_RECORD:
437                 b_remove = true;
438                 break;
439             case INPUT_EVENT_VOUT:
440             case INPUT_EVENT_AOUT:
441             case INPUT_EVENT_DEAD:
442                 b_remove = false;
443                 break;
444             default:
445                 return VLC_SUCCESS;
446         }
447         label <<  pVariable << "_" << newVal.i_int;
448         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal,
449                                             &VlcProc::on_intf_event_changed,
450                                             label.str() );
451         if( pCmd )
452             pQueue->push( CmdGenericPtr( pCmd ), b_remove );
453
454         return VLC_SUCCESS;
455     }
456
457     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
458     return VLC_EGENERIC;
459 }
460
461
462 #define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
463 #define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
464 #define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
465 #define SET_STRING(m,v)       ((VarString*)(m).get())->set(v)
466 #define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->set(v,b)
467
468 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
469 {
470     input_item_t *p_item = static_cast<input_item_t*>(newVal.p_address);
471
472     // Update short name
473     char *psz_name = input_item_GetName( p_item );
474     SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
475     free( psz_name );
476
477     // Update local path (if possible) or full uri
478     char *psz_uri = input_item_GetURI( p_item );
479     char *psz_path = make_path( psz_uri );
480     char *psz_save = psz_path ? psz_path : psz_uri;
481     SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_save ) );
482     free( psz_path );
483     free( psz_uri );
484
485     // Update art uri
486     char *psz_art = input_item_GetArtURL( p_item );
487     SET_STRING( m_cVarStreamArt, string( psz_art ? psz_art : "" ) );
488     free( psz_art );
489
490     // Update playtree
491     getPlaytreeVar().onUpdateCurrent( true );
492 }
493
494 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
495 {
496     input_thread_t* pInput = (input_thread_t*) p_obj;
497
498     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
499
500     if( !getIntf()->p_sys->p_input )
501     {
502         msg_Dbg( getIntf(), "new input %p detected", pInput );
503
504         getIntf()->p_sys->p_input = pInput;
505         vlc_object_hold( pInput );
506     }
507
508     switch( newVal.i_int )
509     {
510         case INPUT_EVENT_STATE:
511         {
512             int state = var_GetInteger( pInput, "state" );
513             SET_BOOL( m_cVarStopped, false );
514             SET_BOOL( m_cVarPlaying, state != PAUSE_S );
515             SET_BOOL( m_cVarPaused, state == PAUSE_S );
516             break;
517         }
518
519         case INPUT_EVENT_POSITION:
520         {
521             float pos = var_GetFloat( pInput, "position" );
522             SET_STREAMTIME( m_cVarTime, pos, false );
523             SET_BOOL( m_cVarSeekable, pos != 0.0 );
524             break;
525         }
526
527         case INPUT_EVENT_ES:
528         {
529             // Do we have audio
530             vlc_value_t audio_es;
531             var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
532                             &audio_es, NULL );
533             SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
534             break;
535         }
536
537         case INPUT_EVENT_VOUT:
538         {
539             vout_thread_t* pVout = input_GetVout( pInput );
540             SET_BOOL( m_cVarHasVout, pVout != NULL );
541             if( !pVout || pVout == m_pVout )
542             {
543                 // end of input or vout reuse (nothing to do)
544                 if( pVout )
545                     vlc_object_release( pVout );
546                 break;
547             }
548             if( m_pVout )
549             {
550                 // remove previous Vout callbacks
551                 var_DelCallback( m_pVout, "mouse-moved",
552                                  onGenericCallback, this );
553                 vlc_object_release( m_pVout );
554                 m_pVout = NULL;
555             }
556
557             // add new Vout callbackx
558             var_AddCallback( pVout, "mouse-moved",
559                              onGenericCallback, this );
560             m_pVout = pVout;
561             break;
562         }
563
564         case INPUT_EVENT_AOUT:
565         {
566             aout_instance_t* pAout = input_GetAout( pInput );
567
568             // end of input or aout reuse (nothing to do)
569             if( !pAout || pAout == m_pAout )
570             {
571                 if( pAout )
572                     vlc_object_release( pAout );
573                 break;
574             }
575
576             // remove previous Aout if any
577             if( m_pAout )
578             {
579                 var_DelCallback( m_pAout, "audio-filter",
580                                  onGenericCallback, this );
581                 if( m_bEqualizer_started )
582                 {
583                     var_DelCallback( m_pAout, "equalizer-bands",
584                                      onEqBandsChange, this );
585                     var_DelCallback( m_pAout, "equalizer-preamp",
586                                      onEqPreampChange, this );
587                 }
588                 vlc_object_release( m_pAout );
589                 m_pAout = NULL;
590                 m_bEqualizer_started = false;
591             }
592
593             // New Aout (addCallbacks)
594             var_AddCallback( pAout, "audio-filter", onGenericCallback, this );
595
596             char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
597             bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
598             free( pFilters );
599             SET_BOOL( m_cVarEqualizer, b_equalizer );
600             if( b_equalizer )
601             {
602                 var_AddCallback( pAout, "equalizer-bands",
603                               onEqBandsChange, this );
604                 var_AddCallback( pAout, "equalizer-preamp",
605                               onEqPreampChange, this );
606                 m_bEqualizer_started = true;
607             }
608             m_pAout = pAout;
609             break;
610         }
611
612         case INPUT_EVENT_CHAPTER:
613         {
614             vlc_value_t chapters_count;
615             var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
616                         &chapters_count, NULL );
617             SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
618             break;
619         }
620
621         case INPUT_EVENT_RECORD:
622             SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
623             break;
624
625         case INPUT_EVENT_DEAD:
626             msg_Dbg( getIntf(), "end of input detected for %p", pInput );
627
628             var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
629             var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
630             var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
631             var_DelCallback( pInput, "can-record" , onGenericCallback, this );
632             vlc_object_release( pInput );
633             getIntf()->p_sys->p_input = NULL;
634             reset_input();
635             break;
636
637         default:
638             break;
639     }
640 }
641
642 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
643 {
644     input_thread_t* pInput = (input_thread_t*) p_obj;
645
646     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
647
648     int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
649     SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
650 }
651
652 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
653 {
654     input_thread_t* pInput = (input_thread_t*) p_obj;
655
656     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
657
658     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
659     SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
660 }
661
662 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
663 {
664     input_thread_t* pInput = (input_thread_t*) p_obj;
665
666     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
667
668     SET_BOOL( m_cVarRecordable, var_GetBool(  pInput, "can-record" ) );
669 }
670
671 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
672 {
673     playlist_t* pPlaylist = (playlist_t*) p_obj;
674
675     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
676 }
677
678 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
679 {
680     playlist_t* pPlaylist = (playlist_t*) p_obj;
681
682     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
683 }
684
685 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
686 {
687     playlist_t* pPlaylist = (playlist_t*) p_obj;
688
689     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
690 }
691
692 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
693 {
694     (void)p_obj; (void)newVal;
695     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
696
697     audio_volume_t volume;
698     aout_VolumeGet( pPlaylist, &volume );
699     SET_VOLUME( m_cVarVolume, volume, false );
700     SET_BOOL( m_cVarMute, volume == 0 );
701 }
702
703 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
704 {
705     aout_instance_t* pAout = (aout_instance_t*) p_obj;
706
707     char *pFilters = newVal.psz_string;
708
709     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
710     SET_BOOL( m_cVarEqualizer, b_equalizer );
711     if( b_equalizer && !m_bEqualizer_started )
712     {
713         var_AddCallback( pAout, "equalizer-bands", onEqBandsChange, this );
714         var_AddCallback( pAout, "equalizer-preamp", onEqPreampChange, this );
715         m_bEqualizer_started = true;
716     }
717 }
718
719 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
720 {
721     (void)p_obj;
722     bool b_fullscreen = getFullscreenVar().get();
723
724     if( !b_fullscreen )
725     {
726         if( newVal.b_bool )
727         {
728             // Create a raise all command
729             CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
730                 getIntf()->p_sys->p_theme->getWindowManager() );
731
732             // Push the command in the asynchronous command queue
733             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
734             pQueue->push( CmdGenericPtr( pCmd ) );
735         }
736     }
737     else
738     {
739         VoutManager* pVoutManager =  VoutManager::instance( getIntf() );
740         FscWindow *pWin = pVoutManager->getFscWindow();
741         if( pWin )
742         {
743             bool b_visible = pWin->getVisibleVar().get();
744             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
745
746             if( !b_visible )
747             {
748                CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
749                              getIntf()->p_sys->p_theme->getWindowManager(),
750                              *pWin );
751                pQueue->push( CmdGenericPtr( pCmd ) );
752             }
753             else
754             {
755                CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
756                               getIntf()->p_sys->p_theme->getWindowManager(),
757                               *pWin );
758                pQueue->push( CmdGenericPtr( pCmd ) );
759             }
760         }
761     }
762 }
763
764 void VlcProc::on_mouse_moved_changed( vlc_object_t* p_obj, vlc_value_t newVal )
765 {
766     FscWindow* pFscWindow = VoutManager::instance( getIntf() )->getFscWindow();
767     if( pFscWindow )
768         pFscWindow->onMouseMoved();
769 }
770
771 void VlcProc::reset_input()
772 {
773     SET_BOOL( m_cVarSeekable, false );
774     SET_BOOL( m_cVarRecordable, false );
775     SET_BOOL( m_cVarRecording, false );
776     SET_BOOL( m_cVarDvdActive, false );
777     SET_BOOL( m_cVarHasAudio, false );
778     SET_BOOL( m_cVarHasVout, false );
779     SET_BOOL( m_cVarStopped, true );
780     SET_BOOL( m_cVarPlaying, false );
781     SET_BOOL( m_cVarPaused, false );
782
783     SET_STREAMTIME( m_cVarTime, 0, false );
784     SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
785     SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
786     SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
787     SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
788
789     getPlaytreeVar().onUpdateCurrent( false );
790 }
791
792 void VlcProc::init_variables()
793 {
794     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
795
796     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
797     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
798     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
799
800     audio_volume_t volume;
801     aout_VolumeGet( pPlaylist, &volume );
802     SET_VOLUME( m_cVarVolume, volume, false );
803     SET_BOOL( m_cVarMute, volume == 0 );
804
805     update_equalizer();
806 }
807
808 void VlcProc::update_equalizer()
809 {
810
811     char *pFilters;
812     if( m_pAout )
813         pFilters = var_GetNonEmptyString( m_pAout, "audio-filter" );
814     else
815         pFilters = var_InheritString( getIntf(), "audio-filter" );
816
817     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
818     free( pFilters );
819
820     SET_BOOL( m_cVarEqualizer, b_equalizer );
821 }
822
823 void VlcProc::setFullscreenVar( bool b_fullscreen )
824 {
825     SET_BOOL( m_cVarFullscreen, b_fullscreen );
826 }
827
828 #undef  SET_BOOL
829 #undef  SET_STREAMTIME
830 #undef  SET_TEXT
831 #undef  SET_STRING
832 #undef  SET_VOLUME