]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
skins2: use the "mute" variable
[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_sys->p_playlist, "mute" )
159     ADD_CALLBACK( pIntf->p_libvlc, "intf-toggle-fscontrol" )
160
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_sys->p_playlist, "mute",
206                      onGenericCallback, this );
207     var_DelCallback( getIntf()->p_libvlc, "intf-toggle-fscontrol",
208                      onGenericCallback, this );
209
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     CmdItemUpdate *pCmdTree = new CmdItemUpdate( 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( "volume", on_volume_changed, true )
371     ADD_CALLBACK_ENTRY( "mute", on_mute_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_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
448 {
449     input_thread_t* pInput = (input_thread_t*) p_obj;
450
451     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
452
453     if( !getIntf()->p_sys->p_input )
454     {
455         msg_Dbg( getIntf(), "new input %p detected", pInput );
456
457         getIntf()->p_sys->p_input = pInput;
458         vlc_object_hold( pInput );
459
460         // update global variables pertaining to this input
461         update_current_input();
462
463         // ensure the playtree is also updated
464         // (highlights the new item to be played back)
465         getPlaytreeVar().onUpdateCurrent( true );
466     }
467
468     switch( newVal.i_int )
469     {
470         case INPUT_EVENT_STATE:
471         {
472             int state = var_GetInteger( pInput, "state" );
473             SET_BOOL( m_cVarStopped, false );
474             SET_BOOL( m_cVarPlaying, state != PAUSE_S );
475             SET_BOOL( m_cVarPaused, state == PAUSE_S );
476             break;
477         }
478
479         case INPUT_EVENT_POSITION:
480         {
481             float pos = var_GetFloat( pInput, "position" );
482             SET_STREAMTIME( m_cVarTime, pos, false );
483             SET_BOOL( m_cVarSeekable, pos != 0.0 );
484             break;
485         }
486
487         case INPUT_EVENT_RATE:
488         {
489             float rate = var_GetFloat( pInput, "rate" );
490             char* buffer;
491             if( asprintf( &buffer, "%.3g", rate ) != -1 )
492             {
493                 SET_TEXT( m_cVarSpeed, UString( getIntf(), buffer ) );
494                 free( buffer );
495             }
496             break;
497         }
498
499         case INPUT_EVENT_ES:
500         {
501             // Do we have audio
502             vlc_value_t audio_es;
503             var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
504                             &audio_es, NULL );
505             SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
506             break;
507         }
508
509         case INPUT_EVENT_VOUT:
510         {
511             vout_thread_t* pVout = input_GetVout( pInput );
512             SET_BOOL( m_cVarHasVout, pVout != NULL );
513             if( !pVout || pVout == m_pVout )
514             {
515                 // end of input or vout reuse (nothing to do)
516                 if( pVout )
517                     vlc_object_release( pVout );
518                 break;
519             }
520             if( m_pVout )
521             {
522                 // remove previous Vout callbacks
523                 var_DelCallback( m_pVout, "mouse-moved",
524                                  onGenericCallback, this );
525                 vlc_object_release( m_pVout );
526                 m_pVout = NULL;
527             }
528
529             // add new Vout callbackx
530             var_AddCallback( pVout, "mouse-moved",
531                              onGenericCallback, this );
532             m_pVout = pVout;
533             break;
534         }
535
536         case INPUT_EVENT_AOUT:
537         {
538             audio_output_t* pAout = input_GetAout( pInput );
539
540             // end of input or aout reuse (nothing to do)
541             if( !pAout || pAout == m_pAout )
542             {
543                 if( pAout )
544                     vlc_object_release( pAout );
545                 break;
546             }
547
548             // remove previous Aout if any
549             if( m_pAout )
550             {
551                 var_DelCallback( m_pAout, "audio-filter",
552                                  onGenericCallback, this );
553                 if( m_bEqualizer_started )
554                 {
555                     var_DelCallback( m_pAout, "equalizer-bands",
556                                      onEqBandsChange, this );
557                     var_DelCallback( m_pAout, "equalizer-preamp",
558                                      onEqPreampChange, this );
559                 }
560                 vlc_object_release( m_pAout );
561                 m_pAout = NULL;
562                 m_bEqualizer_started = false;
563             }
564
565             // New Aout (addCallbacks)
566             var_AddCallback( pAout, "audio-filter", onGenericCallback, this );
567
568             char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
569             bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
570             free( pFilters );
571             SET_BOOL( m_cVarEqualizer, b_equalizer );
572             if( b_equalizer )
573             {
574                 var_AddCallback( pAout, "equalizer-bands",
575                               onEqBandsChange, this );
576                 var_AddCallback( pAout, "equalizer-preamp",
577                               onEqPreampChange, this );
578                 m_bEqualizer_started = true;
579             }
580             m_pAout = pAout;
581             break;
582         }
583
584         case INPUT_EVENT_CHAPTER:
585         {
586             vlc_value_t chapters_count;
587             var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
588                         &chapters_count, NULL );
589             SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
590             break;
591         }
592
593         case INPUT_EVENT_RECORD:
594             SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
595             break;
596
597         case INPUT_EVENT_DEAD:
598             msg_Dbg( getIntf(), "end of input detected for %p", pInput );
599
600             var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
601             var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
602             var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
603             var_DelCallback( pInput, "can-record" , onGenericCallback, this );
604             vlc_object_release( pInput );
605             getIntf()->p_sys->p_input = NULL;
606             reset_input();
607             break;
608
609         default:
610             break;
611     }
612 }
613
614 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
615 {
616     (void)newVal;
617     input_thread_t* pInput = (input_thread_t*) p_obj;
618
619     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
620
621     int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
622     SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
623 }
624
625 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
626 {
627     (void)newVal;
628     input_thread_t* pInput = (input_thread_t*) p_obj;
629
630     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
631
632     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
633     SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
634 }
635
636 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
637 {
638     (void)newVal;
639     input_thread_t* pInput = (input_thread_t*) p_obj;
640
641     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
642
643     SET_BOOL( m_cVarRecordable, var_GetBool(  pInput, "can-record" ) );
644 }
645
646 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
647 {
648     (void)newVal;
649     playlist_t* pPlaylist = (playlist_t*) p_obj;
650
651     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
652 }
653
654 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
655 {
656     (void)newVal;
657     playlist_t* pPlaylist = (playlist_t*) p_obj;
658
659     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
660 }
661
662 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
663 {
664     (void)newVal;
665     playlist_t* pPlaylist = (playlist_t*) p_obj;
666
667     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
668 }
669
670 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
671 {
672     (void)p_obj; (void)newVal;
673     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
674
675     SET_VOLUME( m_cVarVolume, var_GetFloat( pPlaylist, "volume" ), false );
676 }
677
678 void VlcProc::on_mute_changed( vlc_object_t* p_obj, vlc_value_t newVal )
679 {
680     (void)p_obj;
681     SET_BOOL( m_cVarMute, newVal.b_bool );
682 }
683
684 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
685 {
686     (void)newVal;
687     audio_output_t* pAout = (audio_output_t*) p_obj;
688
689     char *pFilters = newVal.psz_string;
690
691     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
692     SET_BOOL( m_cVarEqualizer, b_equalizer );
693     if( b_equalizer && !m_bEqualizer_started )
694     {
695         var_AddCallback( pAout, "equalizer-bands", onEqBandsChange, this );
696         var_AddCallback( pAout, "equalizer-preamp", onEqPreampChange, this );
697         m_bEqualizer_started = true;
698     }
699 }
700
701 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
702 {
703     (void)p_obj; (void)newVal;
704     bool b_fullscreen = getFullscreenVar().get();
705
706     if( !b_fullscreen )
707     {
708         if( newVal.b_bool )
709         {
710             // Create a raise all command
711             CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
712                 getIntf()->p_sys->p_theme->getWindowManager() );
713
714             // Push the command in the asynchronous command queue
715             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
716             pQueue->push( CmdGenericPtr( pCmd ) );
717         }
718     }
719     else
720     {
721         VoutManager* pVoutManager =  VoutManager::instance( getIntf() );
722         FscWindow *pWin = pVoutManager->getFscWindow();
723         if( pWin )
724         {
725             bool b_visible = pWin->getVisibleVar().get();
726             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
727
728             if( !b_visible )
729             {
730                CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
731                              getIntf()->p_sys->p_theme->getWindowManager(),
732                              *pWin );
733                pQueue->push( CmdGenericPtr( pCmd ) );
734             }
735             else
736             {
737                CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
738                               getIntf()->p_sys->p_theme->getWindowManager(),
739                               *pWin );
740                pQueue->push( CmdGenericPtr( pCmd ) );
741             }
742         }
743     }
744 }
745
746 void VlcProc::on_mouse_moved_changed( vlc_object_t* p_obj, vlc_value_t newVal )
747 {
748     (void)p_obj; (void)newVal;
749     FscWindow* pFscWindow = VoutManager::instance( getIntf() )->getFscWindow();
750     if( pFscWindow )
751         pFscWindow->onMouseMoved();
752 }
753
754 void VlcProc::reset_input()
755 {
756     SET_BOOL( m_cVarSeekable, false );
757     SET_BOOL( m_cVarRecordable, false );
758     SET_BOOL( m_cVarRecording, false );
759     SET_BOOL( m_cVarDvdActive, false );
760     SET_BOOL( m_cVarHasAudio, false );
761     SET_BOOL( m_cVarHasVout, false );
762     SET_BOOL( m_cVarStopped, true );
763     SET_BOOL( m_cVarPlaying, false );
764     SET_BOOL( m_cVarPaused, false );
765
766     SET_STREAMTIME( m_cVarTime, 0, false );
767     SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
768     SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
769     SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
770     SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
771
772     getPlaytreeVar().onUpdateCurrent( false );
773 }
774
775 void VlcProc::init_variables()
776 {
777     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
778
779     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
780     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
781     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
782
783     SET_VOLUME( m_cVarVolume, var_GetFloat( pPlaylist, "volume" ), false );
784     SET_BOOL( m_cVarMute, var_GetBool( pPlaylist, "mute" ) );
785
786     update_equalizer();
787 }
788
789
790 void VlcProc::update_current_input()
791 {
792     input_thread_t* pInput = getIntf()->p_sys->p_input;
793     if( !pInput )
794         return;
795
796     input_item_t *pItem = input_GetItem( pInput );
797     if( pItem )
798     {
799         // Update short name
800         char *psz_name = input_item_GetTitle( pItem );
801         if( EMPTY_STR( psz_name ) )
802         {
803             free( psz_name );
804             psz_name = input_item_GetName( pItem );
805         }
806         if( !psz_name )
807             psz_name = strdup ( "" );
808         SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
809         free( psz_name );
810
811         // Update local path (if possible) or full uri
812         char *psz_uri = input_item_GetURI( pItem );
813         char *psz_path = make_path( psz_uri );
814         char *psz_save = psz_path ? psz_path : psz_uri;
815         SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_save ) );
816         free( psz_path );
817         free( psz_uri );
818
819         // Update art uri
820         char *psz_art = input_item_GetArtURL( pItem );
821         SET_STRING( m_cVarStreamArt, string( psz_art ? psz_art : "" ) );
822         free( psz_art );
823     }
824 }
825
826 void VlcProc::update_equalizer()
827 {
828
829     char *pFilters;
830     if( m_pAout )
831         pFilters = var_GetNonEmptyString( m_pAout, "audio-filter" );
832     else
833         pFilters = var_InheritString( getIntf(), "audio-filter" );
834
835     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
836     free( pFilters );
837
838     SET_BOOL( m_cVarEqualizer, b_equalizer );
839 }
840
841 void VlcProc::setFullscreenVar( bool b_fullscreen )
842 {
843     SET_BOOL( m_cVarFullscreen, b_fullscreen );
844 }
845
846 #undef  SET_BOOL
847 #undef  SET_STREAMTIME
848 #undef  SET_TEXT
849 #undef  SET_STRING
850 #undef  SET_VOLUME