]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
76f2ca7924454c79140062c0ea7e65c6798ca729
[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_libvlc, "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_libvlc, "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 = (playlist_add_t*)malloc( sizeof(
291                                                 playlist_add_t ) ) ;
292
293     memcpy( p_add, newVal.p_address, sizeof( playlist_add_t ) ) ;
294
295     CmdGenericPtr ptrTree;
296     CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
297                                                              p_add );
298     ptrTree = CmdGenericPtr( pCmdTree );
299
300     // Push the command in the asynchronous command queue
301     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
302     pQueue->push( ptrTree , false );
303
304     return VLC_SUCCESS;
305 }
306
307 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
308                            vlc_value_t oldVal, vlc_value_t newVal,
309                            void *pParam )
310 {
311     VlcProc *pThis = (VlcProc*)pParam;
312
313     int i_id = newVal.i_int;
314
315     CmdGenericPtr ptrTree;
316     CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
317                                                          i_id);
318     ptrTree = CmdGenericPtr( pCmdTree );
319
320     // Push the command in the asynchronous command queue
321     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
322     pQueue->push( ptrTree , false );
323
324     return VLC_SUCCESS;
325 }
326
327
328 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
329                            vlc_value_t oldVal, vlc_value_t newVal,
330                            void *pParam )
331 {
332     VlcProc *pThis = (VlcProc*)pParam;
333
334     // Create a playlist notify command
335     CmdChangeSkin *pCmd =
336         new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
337
338     // Push the command in the asynchronous command queue
339     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
340     pQueue->push( CmdGenericPtr( pCmd ) );
341
342     return VLC_SUCCESS;
343 }
344
345 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
346                             vlc_value_t oldVal, vlc_value_t newVal,
347                             void *pParam )
348 {
349     VlcProc *pThis = (VlcProc*)pParam;
350     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
351
352     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
353     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
354     pQueue->push( CmdGenericPtr( pCmd ) );
355     return VLC_SUCCESS;
356 }
357
358 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
359                               vlc_value_t oldVal, vlc_value_t newVal,
360                               void *pParam )
361 {
362     VlcProc *pThis = (VlcProc*)pParam;
363
364     // Post a set equalizer bands command
365     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
366                                              pThis->m_varEqBands,
367                                              newVal.psz_string );
368     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
369     pQueue->push( CmdGenericPtr( pCmd ) );
370
371     return VLC_SUCCESS;
372 }
373
374
375 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
376                                vlc_value_t oldVal, vlc_value_t newVal,
377                                void *pParam )
378 {
379     VlcProc *pThis = (VlcProc*)pParam;
380     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
381
382     // Post a set preamp command
383     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
384                                               (newVal.f_float + 20.0) / 40.0 );
385     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
386     pQueue->push( CmdGenericPtr( pCmd ) );
387
388     return VLC_SUCCESS;
389 }
390
391
392 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
393                                 vlc_value_t oldVal, vlc_value_t newVal,
394                                 void *pParam )
395 {
396     VlcProc *pThis = (VlcProc*)pParam;
397     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
398
399     CmdGeneric *pCmd = NULL;
400
401 #define ADD_CALLBACK_ENTRY( var, label ) \
402     { \
403     if( strcmp( pVariable, var ) == 0 ) \
404         pCmd = new Cmd_##label( pThis->getIntf(), pObj, newVal ); \
405     }
406
407     ADD_CALLBACK_ENTRY( "item-current", item_current_changed )
408     ADD_CALLBACK_ENTRY( "volume-change", volume_changed )
409
410     ADD_CALLBACK_ENTRY( "intf-event", intf_event_changed )
411     ADD_CALLBACK_ENTRY( "bit-rate", bit_rate_changed )
412     ADD_CALLBACK_ENTRY( "sample-rate", sample_rate_changed )
413     ADD_CALLBACK_ENTRY( "can-record", can_record_changed )
414
415     ADD_CALLBACK_ENTRY( "random", random_changed )
416     ADD_CALLBACK_ENTRY( "loop", loop_changed )
417     ADD_CALLBACK_ENTRY( "repeat", repeat_changed )
418
419     ADD_CALLBACK_ENTRY( "audio-filter", audio_filter_changed )
420
421     ADD_CALLBACK_ENTRY( "intf-show", intf_show_changed )
422
423 #undef ADD_CALLBACK_ENTRY
424
425     if( pCmd )
426         pQueue->push( CmdGenericPtr( pCmd ), false );
427     else
428         msg_Err( pObj, "no Callback entry provided for %s", pVariable );
429
430     return VLC_SUCCESS;
431 }
432
433 #define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
434 #define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
435 #define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
436 #define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->set(v,b)
437
438 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
439 {
440     input_item_t *p_item = static_cast<input_item_t*>(newVal.p_address);
441
442     // Update short name
443     char *psz_name = input_item_GetName( p_item );
444     SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
445     free( psz_name );
446
447     // Update full uri
448     char *psz_uri = input_item_GetURI( p_item );
449     SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_uri ) );
450     free( psz_uri );
451
452     // Update playtree
453     getPlaytreeVar().onUpdateCurrent( true );
454 }
455
456 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
457 {
458     input_thread_t* pInput = (input_thread_t*) p_obj;
459
460     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
461
462     if( !getIntf()->p_sys->p_input )
463     {
464         msg_Dbg( getIntf(), "new input %p detected", pInput );
465
466         getIntf()->p_sys->p_input = pInput;
467         vlc_object_hold( pInput );
468     }
469
470     switch( newVal.i_int )
471     {
472         case INPUT_EVENT_STATE:
473         {
474             int state = var_GetInteger( pInput, "state" );
475             SET_BOOL( m_cVarStopped, false );
476             SET_BOOL( m_cVarPlaying, state != PAUSE_S );
477             SET_BOOL( m_cVarPaused, state == PAUSE_S );
478             break;
479         }
480
481         case INPUT_EVENT_POSITION:
482         {
483             float pos = var_GetFloat( pInput, "position" );
484             SET_STREAMTIME( m_cVarTime, pos, false );
485             SET_BOOL( m_cVarSeekable, pos != 0.0 );
486             break;
487         }
488
489         case INPUT_EVENT_ES:
490         {
491             // Do we have audio
492             vlc_value_t audio_es;
493             var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
494                             &audio_es, NULL );
495             SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
496             break;
497         }
498
499         case INPUT_EVENT_VOUT:
500         {
501             vout_thread_t* pVout = input_GetVout( pInput );
502             SET_BOOL( m_cVarHasVout, pVout != NULL );
503             if( pVout )
504             {
505                 SET_BOOL( m_cVarFullscreen,
506                                          var_GetBool( pVout, "fullscreen" ) );
507                 vlc_object_release( pVout );
508             }
509             break;
510         }
511
512         case INPUT_EVENT_AOUT:
513         {
514             aout_instance_t* pAout = input_GetAout( pInput );
515
516             // end of input or aout reuse (nothing to do)
517             if( !pAout || pAout == m_pAout )
518             {
519                 if( pAout )
520                     vlc_object_release( pAout );
521                 break;
522             }
523
524             // remove previous Aout if any
525             if( m_pAout )
526             {
527                 var_DelCallback( m_pAout, "audio-filter",
528                                  onGenericCallback, this );
529                 if( m_bEqualizer_started )
530                 {
531                     var_DelCallback( m_pAout, "equalizer-bands",
532                                      onEqBandsChange, this );
533                     var_DelCallback( m_pAout, "equalizer-preamp",
534                                      onEqPreampChange, this );
535                 }
536                 vlc_object_release( m_pAout );
537                 m_pAout = NULL;
538                 m_bEqualizer_started = false;
539             }
540
541             // New Aout (addCallbacks)
542             var_AddCallback( pAout, "audio-filter", onGenericCallback, this );
543
544             char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
545             bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
546             free( pFilters );
547             SET_BOOL( m_cVarEqualizer, b_equalizer );
548             if( b_equalizer )
549             {
550                 var_AddCallback( pAout, "equalizer-bands",
551                               onEqBandsChange, this );
552                 var_AddCallback( pAout, "equalizer-preamp",
553                               onEqPreampChange, this );
554                 m_bEqualizer_started = true;
555             }
556             m_pAout = pAout;
557             break;
558         }
559
560         case INPUT_EVENT_CHAPTER:
561         {
562             vlc_value_t chapters_count;
563             var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
564                         &chapters_count, NULL );
565             SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
566             break;
567         }
568
569         case INPUT_EVENT_RECORD:
570             SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
571             break;
572
573         case INPUT_EVENT_DEAD:
574             msg_Dbg( getIntf(), "end of input detected for %p", pInput );
575
576             var_DelCallback( pInput, "intf-event", onGenericCallback, this );
577             var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
578             var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
579             var_DelCallback( pInput, "can-record" , onGenericCallback, this );
580             vlc_object_release( pInput );
581             getIntf()->p_sys->p_input = NULL;
582             reset_input();
583             break;
584
585         default:
586             break;
587     }
588 }
589
590 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
591 {
592     input_thread_t* pInput = (input_thread_t*) p_obj;
593
594     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
595
596     int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
597     SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
598 }
599
600 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
601 {
602     input_thread_t* pInput = (input_thread_t*) p_obj;
603
604     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
605
606     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
607     SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
608 }
609
610 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
611 {
612     input_thread_t* pInput = (input_thread_t*) p_obj;
613
614     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
615
616     SET_BOOL( m_cVarRecordable, var_GetBool(  pInput, "can-record" ) );
617 }
618
619 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
620 {
621     playlist_t* pPlaylist = (playlist_t*) p_obj;
622
623     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
624 }
625
626 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
627 {
628     playlist_t* pPlaylist = (playlist_t*) p_obj;
629
630     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
631 }
632
633 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
634 {
635     playlist_t* pPlaylist = (playlist_t*) p_obj;
636
637     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
638 }
639
640 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
641 {
642     (void)p_obj; (void)newVal;
643     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
644
645     audio_volume_t volume;
646     aout_VolumeGet( pPlaylist, &volume );
647     SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
648     SET_BOOL( m_cVarMute, volume == 0 );
649 }
650
651 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
652 {
653     aout_instance_t* pAout = (aout_instance_t*) p_obj;
654
655     char *pFilters = newVal.psz_string;
656
657     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
658     SET_BOOL( m_cVarEqualizer, b_equalizer );
659     if( b_equalizer && !m_bEqualizer_started )
660     {
661         var_AddCallback( pAout, "equalizer-bands", onEqBandsChange, this );
662         var_AddCallback( pAout, "equalizer-preamp", onEqPreampChange, this );
663         m_bEqualizer_started = true;
664     }
665 }
666
667 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
668 {
669     (void)p_obj;
670     bool b_fullscreen = getFullscreenVar().get();
671
672     if( !b_fullscreen )
673     {
674         if( newVal.b_bool )
675         {
676             // Create a raise all command
677             CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
678                 getIntf()->p_sys->p_theme->getWindowManager() );
679
680             // Push the command in the asynchronous command queue
681             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
682             pQueue->push( CmdGenericPtr( pCmd ) );
683         }
684     }
685     else
686     {
687         Theme* pTheme =  getIntf()->p_sys->p_theme;
688         TopWindow *pWin = pTheme->getWindowById( "fullscreenController" );
689         if( pWin )
690         {
691             bool b_visible = pWin->getVisibleVar().get();
692             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
693
694             if( !b_visible )
695             {
696                CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
697                              getIntf()->p_sys->p_theme->getWindowManager(),
698                              *pWin );
699                pQueue->push( CmdGenericPtr( pCmd ) );
700             }
701             else
702             {
703                CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
704                               getIntf()->p_sys->p_theme->getWindowManager(),
705                               *pWin );
706                pQueue->push( CmdGenericPtr( pCmd ) );
707             }
708         }
709     }
710 }
711
712 void VlcProc::reset_input()
713 {
714     SET_BOOL( m_cVarSeekable, false );
715     SET_BOOL( m_cVarRecordable, false );
716     SET_BOOL( m_cVarRecording, false );
717     SET_BOOL( m_cVarDvdActive, false );
718     SET_BOOL( m_cVarFullscreen, false );
719     SET_BOOL( m_cVarHasAudio, false );
720     SET_BOOL( m_cVarHasVout, false );
721     SET_BOOL( m_cVarStopped, true );
722     SET_BOOL( m_cVarPlaying, false );
723     SET_BOOL( m_cVarPaused, false );
724
725     SET_STREAMTIME( m_cVarTime, 0, false );
726     SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
727     SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
728     SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
729     SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
730
731     getPlaytreeVar().onUpdateCurrent( false );
732 }
733
734 void VlcProc::init_variables()
735 {
736     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
737
738     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
739     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
740     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
741
742     audio_volume_t volume;
743     aout_VolumeGet( pPlaylist, &volume );
744     SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
745     SET_BOOL( m_cVarMute, volume == 0 );
746
747     update_equalizer();
748 }
749
750 void VlcProc::update_equalizer()
751 {
752
753     char *pFilters;
754     if( m_pAout )
755         pFilters = var_GetNonEmptyString( m_pAout, "audio-filter" );
756     else
757         pFilters = config_GetPsz( getIntf(), "audio-filter" );
758
759     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
760     free( pFilters );
761
762     SET_BOOL( m_cVarEqualizer, b_equalizer );
763 }
764
765 void VlcProc::setFullscreenVar( bool b_fullscreen )
766 {
767     SET_BOOL( m_cVarFullscreen, b_fullscreen );
768 }
769
770 #undef  SET_BOOL
771 #undef  SET_STREAMTIME
772 #undef  SET_TEXT
773 #undef  SET_VOLUME