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