]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
skins2: improve callback system
[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_audio.hpp"
51 #include "../commands/cmd_callbacks.hpp"
52 #include "../utils/var_bool.hpp"
53 #include "../utils/var_string.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_varEqBands( pIntf ), m_pVout( NULL ), m_pAout( NULL ),
78     m_bEqualizer_started( false ), 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     m_cVarStreamArt = VariablePtr( new VarString( getIntf() ) );
134     pVarManager->registerVar( m_cVarStreamArt, "streamArt" );
135
136     // Register the equalizer bands
137     for( int i = 0; i < EqualizerBands::kNbBands; i++)
138     {
139         stringstream ss;
140         ss << "equalizer.band(" << i << ")";
141         pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
142     }
143
144     // XXX WARNING XXX
145     // The object variable callbacks are called from other VLC threads,
146     // so they must put commands in the queue and NOT do anything else
147     // (X11 calls are not reentrant)
148
149 #define ADD_CALLBACK( p_object, var ) \
150     var_AddCallback( p_object, var, onGenericCallback, this );
151
152     ADD_CALLBACK( pIntf->p_sys->p_playlist, "volume-change" )
153     ADD_CALLBACK( pIntf->p_libvlc, "intf-show" )
154
155     ADD_CALLBACK( pIntf->p_sys->p_playlist, "item-current" )
156     ADD_CALLBACK( pIntf->p_sys->p_playlist, "random" )
157     ADD_CALLBACK( pIntf->p_sys->p_playlist, "loop" )
158     ADD_CALLBACK( pIntf->p_sys->p_playlist, "repeat" )
159
160 #undef ADD_CALLBACK
161
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 current input changes
170     var_AddCallback( pIntf->p_sys->p_playlist, "input-current",
171                      onInputNew, this );
172     // Called when a playlist item changed
173     var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
174                      onItemChange, this );
175
176     // Called when we have an interaction dialog to display
177     var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
178     var_AddCallback( pIntf, "interaction", onInteraction, this );
179     interaction_Register( pIntf );
180
181     // initialize variables refering to liblvc and playlist objects
182     init_variables();
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     interaction_Unregister( getIntf() );
203
204     var_DelCallback( getIntf()->p_sys->p_playlist, "volume-change",
205                      onGenericCallback, this );
206     var_DelCallback( getIntf()->p_libvlc, "intf-show",
207                      onGenericCallback, this );
208
209     var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
210                      onGenericCallback, this );
211     var_DelCallback( getIntf()->p_sys->p_playlist, "random",
212                      onGenericCallback, this );
213     var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
214                      onGenericCallback, this );
215     var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
216                      onGenericCallback, this );
217
218     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
219                      onItemAppend, this );
220     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
221                      onItemDelete, this );
222     var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
223                      onInputNew, this );
224     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
225                      onItemChange, this );
226     var_DelCallback( getIntf(), "interaction", onInteraction, this );
227 }
228
229 void VlcProc::manage()
230 {
231     // Did the user request to quit vlc ?
232     if( !vlc_object_alive( getIntf() ) )
233     {
234         // Get the instance of OSFactory
235         OSFactory *pOsFactory = OSFactory::instance( getIntf() );
236
237         // Exit the main OS loop
238         pOsFactory->getOSLoop()->exit();
239
240         return;
241     }
242 }
243
244 void VlcProc::CmdManage::execute()
245 {
246     // Just forward to VlcProc
247     m_pParent->manage();
248 }
249
250
251 int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
252                          vlc_value_t oldval, vlc_value_t newval, void *pParam )
253 {
254     VlcProc *pThis = (VlcProc*)pParam;
255     input_thread_t *pInput = static_cast<input_thread_t*>(newval.p_address);
256
257     var_AddCallback( pInput, "intf-event", onGenericCallback2, pThis );
258     var_AddCallback( pInput, "bit-rate", onGenericCallback, pThis );
259     var_AddCallback( pInput, "sample-rate", onGenericCallback, pThis );
260     var_AddCallback( pInput, "can-record", onGenericCallback, pThis );
261
262     return VLC_SUCCESS;
263 }
264
265
266 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
267                            vlc_value_t oldval, vlc_value_t newval,
268                            void *pParam )
269 {
270     VlcProc *pThis = (VlcProc*)pParam;
271     input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
272
273     // Create a playtree notify command
274     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
275                                                          p_item );
276
277     // Push the command in the asynchronous command queue
278     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
279     pQueue->push( CmdGenericPtr( pCmdTree ), true );
280
281     return VLC_SUCCESS;
282 }
283
284 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
285                            vlc_value_t oldVal, vlc_value_t newVal,
286                            void *pParam )
287 {
288     VlcProc *pThis = (VlcProc*)pParam;
289
290     playlist_add_t *p_add = static_cast<playlist_add_t*>(newVal.p_address);
291
292     CmdGenericPtr ptrTree;
293     CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
294                                                              p_add );
295     ptrTree = CmdGenericPtr( pCmdTree );
296
297     // Push the command in the asynchronous command queue
298     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
299     pQueue->push( ptrTree , false );
300
301     return VLC_SUCCESS;
302 }
303
304 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
305                            vlc_value_t oldVal, vlc_value_t newVal,
306                            void *pParam )
307 {
308     VlcProc *pThis = (VlcProc*)pParam;
309
310     int i_id = newVal.i_int;
311
312     CmdGenericPtr ptrTree;
313     CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
314                                                          i_id);
315     ptrTree = CmdGenericPtr( pCmdTree );
316
317     // Push the command in the asynchronous command queue
318     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
319     pQueue->push( ptrTree , false );
320
321     return VLC_SUCCESS;
322 }
323
324 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
325                             vlc_value_t oldVal, vlc_value_t newVal,
326                             void *pParam )
327 {
328     VlcProc *pThis = (VlcProc*)pParam;
329     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
330
331     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
332     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
333     pQueue->push( CmdGenericPtr( pCmd ) );
334     return VLC_SUCCESS;
335 }
336
337 int VlcProc::onEqBandsChange( 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     // Post a set equalizer bands command
344     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
345                                              pThis->m_varEqBands,
346                                              newVal.psz_string );
347     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
348     pQueue->push( CmdGenericPtr( pCmd ) );
349
350     return VLC_SUCCESS;
351 }
352
353
354 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
355                                vlc_value_t oldVal, vlc_value_t newVal,
356                                void *pParam )
357 {
358     VlcProc *pThis = (VlcProc*)pParam;
359     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
360
361     // Post a set preamp command
362     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
363                                               (newVal.f_float + 20.0) / 40.0 );
364     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
365     pQueue->push( CmdGenericPtr( pCmd ) );
366
367     return VLC_SUCCESS;
368 }
369
370
371 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
372                                 vlc_value_t oldVal, vlc_value_t newVal,
373                                 void *pParam )
374 {
375     VlcProc *pThis = (VlcProc*)pParam;
376     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
377
378 #define ADD_CALLBACK_ENTRY( var, func, remove ) \
379     { \
380     if( strcmp( pVariable, var ) == 0 ) \
381     { \
382         string label = var; \
383         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal, \
384                                             &VlcProc::func, label ); \
385         if( pCmd ) \
386             pQueue->push( CmdGenericPtr( pCmd ), remove ); \
387         return VLC_SUCCESS; \
388     } \
389     }
390
391     ADD_CALLBACK_ENTRY( "item-current", on_item_current_changed, false )
392     ADD_CALLBACK_ENTRY( "volume-change", on_volume_changed, true )
393
394     ADD_CALLBACK_ENTRY( "bit-rate", on_bit_rate_changed, false )
395     ADD_CALLBACK_ENTRY( "sample-rate", on_sample_rate_changed, false )
396     ADD_CALLBACK_ENTRY( "can-record", on_can_record_changed, false )
397
398     ADD_CALLBACK_ENTRY( "random", on_random_changed, false )
399     ADD_CALLBACK_ENTRY( "loop", on_loop_changed, false )
400     ADD_CALLBACK_ENTRY( "repeat", on_repeat_changed, false )
401
402     ADD_CALLBACK_ENTRY( "audio-filter", on_audio_filter_changed, false )
403
404     ADD_CALLBACK_ENTRY( "intf-show", on_intf_show_changed, false )
405
406 #undef ADD_CALLBACK_ENTRY
407
408     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
409     return VLC_EGENERIC;
410 }
411
412
413 int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable,
414                                  vlc_value_t oldVal, vlc_value_t newVal,
415                                  void *pParam )
416 {
417     VlcProc *pThis = (VlcProc*)pParam;
418     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
419
420     /**
421      * For intf-event, commands are labeled based on the value of newVal.
422      *
423      * For some values (e.g position), only keep the latest command
424      * when there are multiple pending commands (remove=true).
425      *
426      * for others, don't discard commands (remove=false)
427      **/
428     if( strcmp( pVariable, "intf-event" ) == 0 )
429     {
430         stringstream label;
431         bool b_remove;
432         switch( newVal.i_int )
433         {
434             case INPUT_EVENT_STATE:
435             case INPUT_EVENT_POSITION:
436             case INPUT_EVENT_ES:
437             case INPUT_EVENT_CHAPTER:
438             case INPUT_EVENT_RECORD:
439                 b_remove = true;
440                 break;
441             case INPUT_EVENT_VOUT:
442             case INPUT_EVENT_AOUT:
443             case INPUT_EVENT_DEAD:
444                 b_remove = false;
445                 break;
446             default:
447                 return VLC_SUCCESS;
448         }
449         label <<  pVariable << "_" << newVal.i_int;
450         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal,
451                                             &VlcProc::on_intf_event_changed,
452                                             label.str() );
453         if( pCmd )
454             pQueue->push( CmdGenericPtr( pCmd ), b_remove );
455
456         return VLC_SUCCESS;
457     }
458
459     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
460     return VLC_EGENERIC;
461 }
462
463
464 #define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
465 #define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
466 #define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
467 #define SET_STRING(m,v)       ((VarString*)(m).get())->set(v)
468 #define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->set(v,b)
469
470 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
471 {
472     input_item_t *p_item = static_cast<input_item_t*>(newVal.p_address);
473
474     // Update short name
475     char *psz_name = input_item_GetName( p_item );
476     SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
477     free( psz_name );
478
479     // Update full uri
480     char *psz_uri = input_item_GetURI( p_item );
481     SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_uri ) );
482     free( psz_uri );
483
484     // Update art uri
485     char *psz_art = input_item_GetArtURL( p_item );
486     SET_STRING( m_cVarStreamArt, string( psz_art ? psz_art : "" ) );
487     free( psz_art );
488
489     // Update playtree
490     getPlaytreeVar().onUpdateCurrent( true );
491 }
492
493 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
494 {
495     input_thread_t* pInput = (input_thread_t*) p_obj;
496
497     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
498
499     if( !getIntf()->p_sys->p_input )
500     {
501         msg_Dbg( getIntf(), "new input %p detected", pInput );
502
503         getIntf()->p_sys->p_input = pInput;
504         vlc_object_hold( pInput );
505     }
506
507     switch( newVal.i_int )
508     {
509         case INPUT_EVENT_STATE:
510         {
511             int state = var_GetInteger( pInput, "state" );
512             SET_BOOL( m_cVarStopped, false );
513             SET_BOOL( m_cVarPlaying, state != PAUSE_S );
514             SET_BOOL( m_cVarPaused, state == PAUSE_S );
515             break;
516         }
517
518         case INPUT_EVENT_POSITION:
519         {
520             float pos = var_GetFloat( pInput, "position" );
521             SET_STREAMTIME( m_cVarTime, pos, false );
522             SET_BOOL( m_cVarSeekable, pos != 0.0 );
523             break;
524         }
525
526         case INPUT_EVENT_ES:
527         {
528             // Do we have audio
529             vlc_value_t audio_es;
530             var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
531                             &audio_es, NULL );
532             SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
533             break;
534         }
535
536         case INPUT_EVENT_VOUT:
537         {
538             vout_thread_t* pVout = input_GetVout( pInput );
539             SET_BOOL( m_cVarHasVout, pVout != NULL );
540             if( pVout )
541                 vlc_object_release( pVout );
542             break;
543         }
544
545         case INPUT_EVENT_AOUT:
546         {
547             aout_instance_t* pAout = input_GetAout( pInput );
548
549             // end of input or aout reuse (nothing to do)
550             if( !pAout || pAout == m_pAout )
551             {
552                 if( pAout )
553                     vlc_object_release( pAout );
554                 break;
555             }
556
557             // remove previous Aout if any
558             if( m_pAout )
559             {
560                 var_DelCallback( m_pAout, "audio-filter",
561                                  onGenericCallback, this );
562                 if( m_bEqualizer_started )
563                 {
564                     var_DelCallback( m_pAout, "equalizer-bands",
565                                      onEqBandsChange, this );
566                     var_DelCallback( m_pAout, "equalizer-preamp",
567                                      onEqPreampChange, this );
568                 }
569                 vlc_object_release( m_pAout );
570                 m_pAout = NULL;
571                 m_bEqualizer_started = false;
572             }
573
574             // New Aout (addCallbacks)
575             var_AddCallback( pAout, "audio-filter", onGenericCallback, this );
576
577             char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
578             bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
579             free( pFilters );
580             SET_BOOL( m_cVarEqualizer, b_equalizer );
581             if( b_equalizer )
582             {
583                 var_AddCallback( pAout, "equalizer-bands",
584                               onEqBandsChange, this );
585                 var_AddCallback( pAout, "equalizer-preamp",
586                               onEqPreampChange, this );
587                 m_bEqualizer_started = true;
588             }
589             m_pAout = pAout;
590             break;
591         }
592
593         case INPUT_EVENT_CHAPTER:
594         {
595             vlc_value_t chapters_count;
596             var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
597                         &chapters_count, NULL );
598             SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
599             break;
600         }
601
602         case INPUT_EVENT_RECORD:
603             SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
604             break;
605
606         case INPUT_EVENT_DEAD:
607             msg_Dbg( getIntf(), "end of input detected for %p", pInput );
608
609             var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
610             var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
611             var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
612             var_DelCallback( pInput, "can-record" , onGenericCallback, this );
613             vlc_object_release( pInput );
614             getIntf()->p_sys->p_input = NULL;
615             reset_input();
616             break;
617
618         default:
619             break;
620     }
621 }
622
623 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
624 {
625     input_thread_t* pInput = (input_thread_t*) p_obj;
626
627     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
628
629     int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
630     SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
631 }
632
633 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
634 {
635     input_thread_t* pInput = (input_thread_t*) p_obj;
636
637     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
638
639     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
640     SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
641 }
642
643 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
644 {
645     input_thread_t* pInput = (input_thread_t*) p_obj;
646
647     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
648
649     SET_BOOL( m_cVarRecordable, var_GetBool(  pInput, "can-record" ) );
650 }
651
652 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
653 {
654     playlist_t* pPlaylist = (playlist_t*) p_obj;
655
656     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
657 }
658
659 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
660 {
661     playlist_t* pPlaylist = (playlist_t*) p_obj;
662
663     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
664 }
665
666 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
667 {
668     playlist_t* pPlaylist = (playlist_t*) p_obj;
669
670     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
671 }
672
673 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
674 {
675     (void)p_obj; (void)newVal;
676     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
677
678     audio_volume_t volume;
679     aout_VolumeGet( pPlaylist, &volume );
680     SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
681     SET_BOOL( m_cVarMute, volume == 0 );
682 }
683
684 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
685 {
686     aout_instance_t* pAout = (aout_instance_t*) p_obj;
687
688     char *pFilters = newVal.psz_string;
689
690     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
691     SET_BOOL( m_cVarEqualizer, b_equalizer );
692     if( b_equalizer && !m_bEqualizer_started )
693     {
694         var_AddCallback( pAout, "equalizer-bands", onEqBandsChange, this );
695         var_AddCallback( pAout, "equalizer-preamp", onEqPreampChange, this );
696         m_bEqualizer_started = true;
697     }
698 }
699
700 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
701 {
702     (void)p_obj;
703     bool b_fullscreen = getFullscreenVar().get();
704
705     if( !b_fullscreen )
706     {
707         if( newVal.b_bool )
708         {
709             // Create a raise all command
710             CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
711                 getIntf()->p_sys->p_theme->getWindowManager() );
712
713             // Push the command in the asynchronous command queue
714             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
715             pQueue->push( CmdGenericPtr( pCmd ) );
716         }
717     }
718     else
719     {
720         Theme* pTheme =  getIntf()->p_sys->p_theme;
721         TopWindow *pWin = pTheme->getWindowById( "fullscreenController" );
722         if( pWin )
723         {
724             bool b_visible = pWin->getVisibleVar().get();
725             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
726
727             if( !b_visible )
728             {
729                CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
730                              getIntf()->p_sys->p_theme->getWindowManager(),
731                              *pWin );
732                pQueue->push( CmdGenericPtr( pCmd ) );
733             }
734             else
735             {
736                CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
737                               getIntf()->p_sys->p_theme->getWindowManager(),
738                               *pWin );
739                pQueue->push( CmdGenericPtr( pCmd ) );
740             }
741         }
742     }
743 }
744
745 void VlcProc::reset_input()
746 {
747     SET_BOOL( m_cVarSeekable, false );
748     SET_BOOL( m_cVarRecordable, false );
749     SET_BOOL( m_cVarRecording, false );
750     SET_BOOL( m_cVarDvdActive, false );
751     SET_BOOL( m_cVarHasAudio, false );
752     SET_BOOL( m_cVarHasVout, false );
753     SET_BOOL( m_cVarStopped, true );
754     SET_BOOL( m_cVarPlaying, false );
755     SET_BOOL( m_cVarPaused, false );
756
757     SET_STREAMTIME( m_cVarTime, 0, false );
758     SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
759     SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
760     SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
761     SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
762
763     getPlaytreeVar().onUpdateCurrent( false );
764 }
765
766 void VlcProc::init_variables()
767 {
768     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
769
770     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
771     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
772     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
773
774     audio_volume_t volume;
775     aout_VolumeGet( pPlaylist, &volume );
776     SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
777     SET_BOOL( m_cVarMute, volume == 0 );
778
779     update_equalizer();
780 }
781
782 void VlcProc::update_equalizer()
783 {
784
785     char *pFilters;
786     if( m_pAout )
787         pFilters = var_GetNonEmptyString( m_pAout, "audio-filter" );
788     else
789         pFilters = var_InheritString( getIntf(), "audio-filter" );
790
791     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
792     free( pFilters );
793
794     SET_BOOL( m_cVarEqualizer, b_equalizer );
795 }
796
797 void VlcProc::setFullscreenVar( bool b_fullscreen )
798 {
799     SET_BOOL( m_cVarFullscreen, b_fullscreen );
800 }
801
802 #undef  SET_BOOL
803 #undef  SET_STREAMTIME
804 #undef  SET_TEXT
805 #undef  SET_STRING
806 #undef  SET_VOLUME