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