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