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