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