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