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