]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
Win32 skins: reorder includes to fix warnings
[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" )
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
182     // initialize variables refering to liblvc and playlist objects
183     init_variables();
184 }
185
186
187 VlcProc::~VlcProc()
188 {
189     m_pTimer->stop();
190     delete( m_pTimer );
191
192     if( m_pAout )
193     {
194         vlc_object_release( m_pAout );
195         m_pAout = NULL;
196     }
197     if( m_pVout )
198     {
199         vlc_object_release( m_pVout );
200         m_pVout = NULL;
201     }
202
203     interaction_Unregister( getIntf() );
204
205     var_DelCallback( getIntf()->p_sys->p_playlist, "volume",
206                      onGenericCallback, this );
207     var_DelCallback( getIntf()->p_libvlc, "intf-show",
208                      onGenericCallback, this );
209
210     var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
211                      onGenericCallback, this );
212     var_DelCallback( getIntf()->p_sys->p_playlist, "random",
213                      onGenericCallback, this );
214     var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
215                      onGenericCallback, this );
216     var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
217                      onGenericCallback, this );
218
219     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
220                      onItemAppend, this );
221     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
222                      onItemDelete, this );
223     var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
224                      onInputNew, this );
225     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
226                      onItemChange, this );
227     var_DelCallback( getIntf(), "interaction", onInteraction, this );
228 }
229
230 void VlcProc::manage()
231 {
232     // Did the user request to quit vlc ?
233     if( !vlc_object_alive( getIntf() ) )
234     {
235         // Get the instance of OSFactory
236         OSFactory *pOsFactory = OSFactory::instance( getIntf() );
237
238         // Exit the main OS loop
239         pOsFactory->getOSLoop()->exit();
240
241         return;
242     }
243 }
244
245 void VlcProc::CmdManage::execute()
246 {
247     // Just forward to VlcProc
248     m_pParent->manage();
249 }
250
251
252 int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
253                          vlc_value_t oldval, vlc_value_t newval, void *pParam )
254 {
255     (void)pObj; (void)pVariable; (void)oldval;
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     (void)pObj; (void)pVariable; (void)oldval;
273     VlcProc *pThis = (VlcProc*)pParam;
274     input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
275
276     // Create a playtree notify command
277     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
278                                                          p_item );
279
280     // Push the command in the asynchronous command queue
281     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
282     pQueue->push( CmdGenericPtr( pCmdTree ), true );
283
284     return VLC_SUCCESS;
285 }
286
287 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
288                            vlc_value_t oldVal, vlc_value_t newVal,
289                            void *pParam )
290 {
291     (void)pObj; (void)pVariable; (void)oldVal;
292     VlcProc *pThis = (VlcProc*)pParam;
293
294     playlist_add_t *p_add = static_cast<playlist_add_t*>(newVal.p_address);
295     CmdPlaytreeAppend *pCmdTree =
296         new CmdPlaytreeAppend( pThis->getIntf(), p_add );
297
298     // Push the command in the asynchronous command queue
299     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
300     pQueue->push( CmdGenericPtr( pCmdTree ), false );
301
302     return VLC_SUCCESS;
303 }
304
305 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
306                            vlc_value_t oldVal, vlc_value_t newVal,
307                            void *pParam )
308 {
309     (void)pObj; (void)pVariable; (void)oldVal;
310     VlcProc *pThis = (VlcProc*)pParam;
311
312     int i_id = newVal.i_int;
313     CmdPlaytreeDelete *pCmdTree =
314         new CmdPlaytreeDelete( pThis->getIntf(), i_id);
315
316     // Push the command in the asynchronous command queue
317     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
318     pQueue->push( CmdGenericPtr( pCmdTree ), false );
319
320     return VLC_SUCCESS;
321 }
322
323 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
324                             vlc_value_t oldVal, vlc_value_t newVal,
325                             void *pParam )
326 {
327     (void)pObj; (void)pVariable; (void)oldVal;
328     VlcProc *pThis = (VlcProc*)pParam;
329     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
330
331     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
332     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
333     pQueue->push( CmdGenericPtr( pCmd ) );
334     return VLC_SUCCESS;
335 }
336
337 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
338                               vlc_value_t oldVal, vlc_value_t newVal,
339                               void *pParam )
340 {
341     (void)pObj; (void)pVariable; (void)oldVal;
342     VlcProc *pThis = (VlcProc*)pParam;
343
344     // Post a set equalizer bands command
345     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
346                                              pThis->m_varEqBands,
347                                              newVal.psz_string );
348     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
349     pQueue->push( CmdGenericPtr( pCmd ) );
350
351     return VLC_SUCCESS;
352 }
353
354
355 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
356                                vlc_value_t oldVal, vlc_value_t newVal,
357                                void *pParam )
358 {
359     (void)pObj; (void)pVariable; (void)oldVal;
360     VlcProc *pThis = (VlcProc*)pParam;
361     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
362
363     // Post a set preamp command
364     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
365                                               (newVal.f_float + 20.0) / 40.0 );
366     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
367     pQueue->push( CmdGenericPtr( pCmd ) );
368
369     return VLC_SUCCESS;
370 }
371
372
373 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
374                                 vlc_value_t oldVal, vlc_value_t newVal,
375                                 void *pParam )
376 {
377     (void)oldVal;
378     VlcProc *pThis = (VlcProc*)pParam;
379     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
380
381 #define ADD_CALLBACK_ENTRY( var, func, remove ) \
382     { \
383     if( strcmp( pVariable, var ) == 0 ) \
384     { \
385         string label = var; \
386         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal, \
387                                             &VlcProc::func, label ); \
388         if( pCmd ) \
389             pQueue->push( CmdGenericPtr( pCmd ), remove ); \
390         return VLC_SUCCESS; \
391     } \
392     }
393
394     ADD_CALLBACK_ENTRY( "item-current", on_item_current_changed, false )
395     ADD_CALLBACK_ENTRY( "volume", on_volume_changed, true )
396
397     ADD_CALLBACK_ENTRY( "bit-rate", on_bit_rate_changed, false )
398     ADD_CALLBACK_ENTRY( "sample-rate", on_sample_rate_changed, false )
399     ADD_CALLBACK_ENTRY( "can-record", on_can_record_changed, false )
400
401     ADD_CALLBACK_ENTRY( "random", on_random_changed, false )
402     ADD_CALLBACK_ENTRY( "loop", on_loop_changed, false )
403     ADD_CALLBACK_ENTRY( "repeat", on_repeat_changed, false )
404
405     ADD_CALLBACK_ENTRY( "audio-filter", on_audio_filter_changed, false )
406
407     ADD_CALLBACK_ENTRY( "intf-show", on_intf_show_changed, false )
408
409     ADD_CALLBACK_ENTRY( "mouse-moved", on_mouse_moved_changed, false )
410
411 #undef ADD_CALLBACK_ENTRY
412
413     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
414     return VLC_EGENERIC;
415 }
416
417
418 int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable,
419                                  vlc_value_t oldVal, vlc_value_t newVal,
420                                  void *pParam )
421 {
422     (void)oldVal;
423     VlcProc *pThis = (VlcProc*)pParam;
424     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
425
426     /**
427      * For intf-event, commands are labeled based on the value of newVal.
428      *
429      * For some values (e.g position), only keep the latest command
430      * when there are multiple pending commands (remove=true).
431      *
432      * for others, don't discard commands (remove=false)
433      **/
434     if( strcmp( pVariable, "intf-event" ) == 0 )
435     {
436         stringstream label;
437         bool b_remove;
438         switch( newVal.i_int )
439         {
440             case INPUT_EVENT_STATE:
441             case INPUT_EVENT_POSITION:
442             case INPUT_EVENT_ES:
443             case INPUT_EVENT_CHAPTER:
444             case INPUT_EVENT_RECORD:
445                 b_remove = true;
446                 break;
447             case INPUT_EVENT_VOUT:
448             case INPUT_EVENT_AOUT:
449             case INPUT_EVENT_DEAD:
450                 b_remove = false;
451                 break;
452             default:
453                 return VLC_SUCCESS;
454         }
455         label <<  pVariable << "_" << newVal.i_int;
456         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal,
457                                             &VlcProc::on_intf_event_changed,
458                                             label.str() );
459         if( pCmd )
460             pQueue->push( CmdGenericPtr( pCmd ), b_remove );
461
462         return VLC_SUCCESS;
463     }
464
465     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
466     return VLC_EGENERIC;
467 }
468
469
470 #define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
471 #define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
472 #define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
473 #define SET_STRING(m,v)       ((VarString*)(m).get())->set(v)
474 #define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->set(v,b)
475
476 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
477 {
478     (void)p_obj;
479     input_item_t *p_item = static_cast<input_item_t*>(newVal.p_address);
480
481     // Update short name
482     char *psz_name = input_item_GetName( p_item );
483     SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
484     free( psz_name );
485
486     // Update local path (if possible) or full uri
487     char *psz_uri = input_item_GetURI( p_item );
488     char *psz_path = make_path( psz_uri );
489     char *psz_save = psz_path ? psz_path : psz_uri;
490     SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_save ) );
491     free( psz_path );
492     free( psz_uri );
493
494     // Update art uri
495     char *psz_art = input_item_GetArtURL( p_item );
496     SET_STRING( m_cVarStreamArt, string( psz_art ? psz_art : "" ) );
497     free( psz_art );
498
499     // Update playtree
500     getPlaytreeVar().onUpdateCurrent( true );
501 }
502
503 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
504 {
505     input_thread_t* pInput = (input_thread_t*) p_obj;
506
507     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
508
509     if( !getIntf()->p_sys->p_input )
510     {
511         msg_Dbg( getIntf(), "new input %p detected", pInput );
512
513         getIntf()->p_sys->p_input = pInput;
514         vlc_object_hold( pInput );
515     }
516
517     switch( newVal.i_int )
518     {
519         case INPUT_EVENT_STATE:
520         {
521             int state = var_GetInteger( pInput, "state" );
522             SET_BOOL( m_cVarStopped, false );
523             SET_BOOL( m_cVarPlaying, state != PAUSE_S );
524             SET_BOOL( m_cVarPaused, state == PAUSE_S );
525             break;
526         }
527
528         case INPUT_EVENT_POSITION:
529         {
530             float pos = var_GetFloat( pInput, "position" );
531             SET_STREAMTIME( m_cVarTime, pos, false );
532             SET_BOOL( m_cVarSeekable, pos != 0.0 );
533             break;
534         }
535
536         case INPUT_EVENT_ES:
537         {
538             // Do we have audio
539             vlc_value_t audio_es;
540             var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
541                             &audio_es, NULL );
542             SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
543             break;
544         }
545
546         case INPUT_EVENT_VOUT:
547         {
548             vout_thread_t* pVout = input_GetVout( pInput );
549             SET_BOOL( m_cVarHasVout, pVout != NULL );
550             if( !pVout || pVout == m_pVout )
551             {
552                 // end of input or vout reuse (nothing to do)
553                 if( pVout )
554                     vlc_object_release( pVout );
555                 break;
556             }
557             if( m_pVout )
558             {
559                 // remove previous Vout callbacks
560                 var_DelCallback( m_pVout, "mouse-moved",
561                                  onGenericCallback, this );
562                 vlc_object_release( m_pVout );
563                 m_pVout = NULL;
564             }
565
566             // add new Vout callbackx
567             var_AddCallback( pVout, "mouse-moved",
568                              onGenericCallback, this );
569             m_pVout = pVout;
570             break;
571         }
572
573         case INPUT_EVENT_AOUT:
574         {
575             aout_instance_t* pAout = input_GetAout( pInput );
576
577             // end of input or aout reuse (nothing to do)
578             if( !pAout || pAout == m_pAout )
579             {
580                 if( pAout )
581                     vlc_object_release( pAout );
582                 break;
583             }
584
585             // remove previous Aout if any
586             if( m_pAout )
587             {
588                 var_DelCallback( m_pAout, "audio-filter",
589                                  onGenericCallback, this );
590                 if( m_bEqualizer_started )
591                 {
592                     var_DelCallback( m_pAout, "equalizer-bands",
593                                      onEqBandsChange, this );
594                     var_DelCallback( m_pAout, "equalizer-preamp",
595                                      onEqPreampChange, this );
596                 }
597                 vlc_object_release( m_pAout );
598                 m_pAout = NULL;
599                 m_bEqualizer_started = false;
600             }
601
602             // New Aout (addCallbacks)
603             var_AddCallback( pAout, "audio-filter", onGenericCallback, this );
604
605             char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
606             bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
607             free( pFilters );
608             SET_BOOL( m_cVarEqualizer, b_equalizer );
609             if( b_equalizer )
610             {
611                 var_AddCallback( pAout, "equalizer-bands",
612                               onEqBandsChange, this );
613                 var_AddCallback( pAout, "equalizer-preamp",
614                               onEqPreampChange, this );
615                 m_bEqualizer_started = true;
616             }
617             m_pAout = pAout;
618             break;
619         }
620
621         case INPUT_EVENT_CHAPTER:
622         {
623             vlc_value_t chapters_count;
624             var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
625                         &chapters_count, NULL );
626             SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
627             break;
628         }
629
630         case INPUT_EVENT_RECORD:
631             SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
632             break;
633
634         case INPUT_EVENT_DEAD:
635             msg_Dbg( getIntf(), "end of input detected for %p", pInput );
636
637             var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
638             var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
639             var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
640             var_DelCallback( pInput, "can-record" , onGenericCallback, this );
641             vlc_object_release( pInput );
642             getIntf()->p_sys->p_input = NULL;
643             reset_input();
644             break;
645
646         default:
647             break;
648     }
649 }
650
651 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
652 {
653     (void)newVal;
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 bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
659     SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
660 }
661
662 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
663 {
664     (void)newVal;
665     input_thread_t* pInput = (input_thread_t*) p_obj;
666
667     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
668
669     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
670     SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
671 }
672
673 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
674 {
675     (void)newVal;
676     input_thread_t* pInput = (input_thread_t*) p_obj;
677
678     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
679
680     SET_BOOL( m_cVarRecordable, var_GetBool(  pInput, "can-record" ) );
681 }
682
683 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
684 {
685     (void)newVal;
686     playlist_t* pPlaylist = (playlist_t*) p_obj;
687
688     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
689 }
690
691 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
692 {
693     (void)newVal;
694     playlist_t* pPlaylist = (playlist_t*) p_obj;
695
696     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
697 }
698
699 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
700 {
701     (void)newVal;
702     playlist_t* pPlaylist = (playlist_t*) p_obj;
703
704     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
705 }
706
707 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
708 {
709     (void)p_obj; (void)newVal;
710     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
711
712     audio_volume_t volume = aout_VolumeGet( pPlaylist );
713     SET_VOLUME( m_cVarVolume, volume, false );
714     SET_BOOL( m_cVarMute, volume == 0 );
715 }
716
717 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
718 {
719     (void)newVal;
720     aout_instance_t* pAout = (aout_instance_t*) p_obj;
721
722     char *pFilters = newVal.psz_string;
723
724     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
725     SET_BOOL( m_cVarEqualizer, b_equalizer );
726     if( b_equalizer && !m_bEqualizer_started )
727     {
728         var_AddCallback( pAout, "equalizer-bands", onEqBandsChange, this );
729         var_AddCallback( pAout, "equalizer-preamp", onEqPreampChange, this );
730         m_bEqualizer_started = true;
731     }
732 }
733
734 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
735 {
736     (void)p_obj; (void)newVal;
737     bool b_fullscreen = getFullscreenVar().get();
738
739     if( !b_fullscreen )
740     {
741         if( newVal.b_bool )
742         {
743             // Create a raise all command
744             CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
745                 getIntf()->p_sys->p_theme->getWindowManager() );
746
747             // Push the command in the asynchronous command queue
748             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
749             pQueue->push( CmdGenericPtr( pCmd ) );
750         }
751     }
752     else
753     {
754         VoutManager* pVoutManager =  VoutManager::instance( getIntf() );
755         FscWindow *pWin = pVoutManager->getFscWindow();
756         if( pWin )
757         {
758             bool b_visible = pWin->getVisibleVar().get();
759             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
760
761             if( !b_visible )
762             {
763                CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
764                              getIntf()->p_sys->p_theme->getWindowManager(),
765                              *pWin );
766                pQueue->push( CmdGenericPtr( pCmd ) );
767             }
768             else
769             {
770                CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
771                               getIntf()->p_sys->p_theme->getWindowManager(),
772                               *pWin );
773                pQueue->push( CmdGenericPtr( pCmd ) );
774             }
775         }
776     }
777 }
778
779 void VlcProc::on_mouse_moved_changed( vlc_object_t* p_obj, vlc_value_t newVal )
780 {
781     (void)p_obj; (void)newVal;
782     FscWindow* pFscWindow = VoutManager::instance( getIntf() )->getFscWindow();
783     if( pFscWindow )
784         pFscWindow->onMouseMoved();
785 }
786
787 void VlcProc::reset_input()
788 {
789     SET_BOOL( m_cVarSeekable, false );
790     SET_BOOL( m_cVarRecordable, false );
791     SET_BOOL( m_cVarRecording, false );
792     SET_BOOL( m_cVarDvdActive, false );
793     SET_BOOL( m_cVarHasAudio, false );
794     SET_BOOL( m_cVarHasVout, false );
795     SET_BOOL( m_cVarStopped, true );
796     SET_BOOL( m_cVarPlaying, false );
797     SET_BOOL( m_cVarPaused, false );
798
799     SET_STREAMTIME( m_cVarTime, 0, false );
800     SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
801     SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
802     SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
803     SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
804
805     getPlaytreeVar().onUpdateCurrent( false );
806 }
807
808 void VlcProc::init_variables()
809 {
810     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
811
812     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
813     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
814     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
815
816     audio_volume_t volume = aout_VolumeGet( pPlaylist );
817     SET_VOLUME( m_cVarVolume, volume, false );
818     SET_BOOL( m_cVarMute, volume == 0 );
819
820     update_equalizer();
821 }
822
823 void VlcProc::update_equalizer()
824 {
825
826     char *pFilters;
827     if( m_pAout )
828         pFilters = var_GetNonEmptyString( m_pAout, "audio-filter" );
829     else
830         pFilters = var_InheritString( getIntf(), "audio-filter" );
831
832     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
833     free( pFilters );
834
835     SET_BOOL( m_cVarEqualizer, b_equalizer );
836 }
837
838 void VlcProc::setFullscreenVar( bool b_fullscreen )
839 {
840     SET_BOOL( m_cVarFullscreen, b_fullscreen );
841 }
842
843 #undef  SET_BOOL
844 #undef  SET_STREAMTIME
845 #undef  SET_TEXT
846 #undef  SET_STRING
847 #undef  SET_VOLUME