dcf3b30c74462cf266fb6edcbab02210f6430243
[vlc.git] / 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 #include <vlc_url.h>
35 #include <vlc_strings.h>
36
37 #include "vlcproc.hpp"
38 #include "os_factory.hpp"
39 #include "os_loop.hpp"
40 #include "os_timer.hpp"
41 #include "var_manager.hpp"
42 #include "vout_manager.hpp"
43 #include "fsc_window.hpp"
44 #include "theme.hpp"
45 #include "window_manager.hpp"
46 #include "../commands/async_queue.hpp"
47 #include "../commands/cmd_change_skin.hpp"
48 #include "../commands/cmd_show_window.hpp"
49 #include "../commands/cmd_quit.hpp"
50 #include "../commands/cmd_resize.hpp"
51 #include "../commands/cmd_vars.hpp"
52 #include "../commands/cmd_dialogs.hpp"
53 #include "../commands/cmd_audio.hpp"
54 #include "../commands/cmd_callbacks.hpp"
55 #include "../utils/var_bool.hpp"
56 #include "../utils/var_string.hpp"
57 #include <sstream>
58
59 #include <assert.h>
60
61 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
62 {
63     if( pIntf->p_sys->p_vlcProc == NULL )
64     {
65         pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
66     }
67
68     return pIntf->p_sys->p_vlcProc;
69 }
70
71
72 void VlcProc::destroy( intf_thread_t *pIntf )
73 {
74     delete pIntf->p_sys->p_vlcProc;
75     pIntf->p_sys->p_vlcProc = NULL;
76 }
77
78 #define SET_BOOL(m,v)         ((VarBoolImpl*)(m).get())->set(v)
79 #define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
80 #define SET_TEXT(m,v)         ((VarText*)(m).get())->set(v)
81 #define SET_STRING(m,v)       ((VarString*)(m).get())->set(v)
82 #define SET_VOLUME(m,v,b)     ((Volume*)(m).get())->setVolume(v,b)
83
84 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
85     m_varEqBands( pIntf ), m_pVout( NULL )
86 {
87     // Create and register VLC variables
88     VarManager *pVarManager = VarManager::instance( getIntf() );
89
90 #define REGISTER_VAR( var, type, name ) \
91     var = VariablePtr( new type( getIntf() ) ); \
92     pVarManager->registerVar( var, name );
93     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
94     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
95     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
96     REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
97     pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
98                               "playtree.slider" );
99     pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
100     pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
101
102     REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
103     REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
104     REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
105
106     /* Input variables */
107     pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
108     REGISTER_VAR( m_cVarTime, StreamTime, "time" )
109     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
110     REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
111
112     REGISTER_VAR( m_cVarRecordable, VarBoolImpl, "vlc.canRecord" )
113     REGISTER_VAR( m_cVarRecording, VarBoolImpl, "vlc.isRecording" )
114
115     /* Vout variables */
116     REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
117     REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
118
119     /* Aout variables */
120     REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
121     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
122     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
123     REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
124     REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
125
126 #undef REGISTER_VAR
127     m_cVarSpeed = VariablePtr( new VarText( getIntf(), false ) );
128     pVarManager->registerVar( m_cVarSpeed, "speed" );
129     SET_TEXT( m_cVarSpeed, UString( getIntf(), "1") );
130     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
131     pVarManager->registerVar( m_cVarStreamName, "streamName" );
132     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
133     pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
134     m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
135     pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
136     m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
137     pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
138     m_cVarStreamArt = VariablePtr( new VarString( getIntf() ) );
139     pVarManager->registerVar( m_cVarStreamArt, "streamArt" );
140
141     // Register the equalizer bands
142     for( int i = 0; i < EqualizerBands::kNbBands; i++)
143     {
144         stringstream ss;
145         ss << "equalizer.band(" << i << ")";
146         pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
147     }
148
149     // XXX WARNING XXX
150     // The object variable callbacks are called from other VLC threads,
151     // so they must put commands in the queue and NOT do anything else
152     // (X11 calls are not reentrant)
153
154 #define ADD_CALLBACK( p_object, var ) \
155     var_AddCallback( p_object, var, onGenericCallback, this );
156
157     ADD_CALLBACK( pIntf->p_sys->p_playlist, "volume" )
158     ADD_CALLBACK( pIntf->p_sys->p_playlist, "mute" )
159     ADD_CALLBACK( pIntf->p_libvlc, "intf-toggle-fscontrol" )
160
161     ADD_CALLBACK( pIntf->p_sys->p_playlist, "random" )
162     ADD_CALLBACK( pIntf->p_sys->p_playlist, "loop" )
163     ADD_CALLBACK( pIntf->p_sys->p_playlist, "repeat" )
164
165 #undef ADD_CALLBACK
166
167     // Called when a playlist item is added
168     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-append",
169                      onItemAppend, this );
170     // Called when a playlist item is deleted
171     // TODO: properly handle item-deleted
172     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-deleted",
173                      onItemDelete, 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
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
185     // initialize variables refering to liblvc and playlist objects
186     init_variables();
187 }
188
189
190 VlcProc::~VlcProc()
191 {
192     if( m_pVout )
193     {
194         vlc_object_release( m_pVout );
195         m_pVout = NULL;
196     }
197
198     var_DelCallback( getIntf()->p_sys->p_playlist, "volume",
199                      onGenericCallback, this );
200     var_DelCallback( getIntf()->p_sys->p_playlist, "mute",
201                      onGenericCallback, this );
202     var_DelCallback( getIntf()->p_libvlc, "intf-toggle-fscontrol",
203                      onGenericCallback, this );
204
205     var_DelCallback( getIntf()->p_sys->p_playlist, "random",
206                      onGenericCallback, this );
207     var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
208                      onGenericCallback, this );
209     var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
210                      onGenericCallback, this );
211
212     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
213                      onItemAppend, this );
214     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
215                      onItemDelete, this );
216     var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
217                      onInputNew, this );
218     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
219                      onItemChange, this );
220     var_DelCallback( getIntf(), "interaction", onInteraction, this );
221 }
222
223 int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
224                          vlc_value_t oldval, vlc_value_t newval, void *pParam )
225 {
226     (void)pObj; (void)pVariable; (void)oldval;
227     VlcProc *pThis = (VlcProc*)pParam;
228     input_thread_t *pInput = static_cast<input_thread_t*>(newval.p_address);
229
230     var_AddCallback( pInput, "intf-event", onGenericCallback2, pThis );
231     var_AddCallback( pInput, "bit-rate", onGenericCallback, pThis );
232     var_AddCallback( pInput, "sample-rate", onGenericCallback, pThis );
233     var_AddCallback( pInput, "can-record", onGenericCallback, pThis );
234
235     return VLC_SUCCESS;
236 }
237
238
239 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
240                            vlc_value_t oldval, vlc_value_t newval,
241                            void *pParam )
242 {
243     (void)pObj; (void)pVariable; (void)oldval;
244     VlcProc *pThis = (VlcProc*)pParam;
245     input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
246
247     // Create a playtree notify command
248     CmdItemUpdate *pCmdTree = new CmdItemUpdate( pThis->getIntf(),
249                                                          p_item );
250
251     // Push the command in the asynchronous command queue
252     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
253     pQueue->push( CmdGenericPtr( pCmdTree ), true );
254
255     return VLC_SUCCESS;
256 }
257
258 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
259                            vlc_value_t oldVal, vlc_value_t newVal,
260                            void *pParam )
261 {
262     (void)pObj; (void)pVariable; (void)oldVal;
263     VlcProc *pThis = (VlcProc*)pParam;
264
265     playlist_add_t *p_add = static_cast<playlist_add_t*>(newVal.p_address);
266     CmdPlaytreeAppend *pCmdTree =
267         new CmdPlaytreeAppend( pThis->getIntf(), p_add );
268
269     // Push the command in the asynchronous command queue
270     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
271     pQueue->push( CmdGenericPtr( pCmdTree ), false );
272
273     return VLC_SUCCESS;
274 }
275
276 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
277                            vlc_value_t oldVal, vlc_value_t newVal,
278                            void *pParam )
279 {
280     (void)pObj; (void)pVariable; (void)oldVal;
281     VlcProc *pThis = (VlcProc*)pParam;
282
283     int i_id = newVal.i_int;
284     CmdPlaytreeDelete *pCmdTree =
285         new CmdPlaytreeDelete( pThis->getIntf(), i_id);
286
287     // Push the command in the asynchronous command queue
288     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
289     pQueue->push( CmdGenericPtr( pCmdTree ), false );
290
291     return VLC_SUCCESS;
292 }
293
294 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
295                             vlc_value_t oldVal, vlc_value_t newVal,
296                             void *pParam )
297 {
298     (void)pObj; (void)pVariable; (void)oldVal;
299     VlcProc *pThis = (VlcProc*)pParam;
300     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
301
302     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
303     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
304     pQueue->push( CmdGenericPtr( pCmd ) );
305     return VLC_SUCCESS;
306 }
307
308 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
309                               vlc_value_t oldVal, vlc_value_t newVal,
310                               void *pParam )
311 {
312     (void)pObj; (void)pVariable; (void)oldVal;
313     VlcProc *pThis = (VlcProc*)pParam;
314
315     // Post a set equalizer bands command
316     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
317                                              pThis->m_varEqBands,
318                                              newVal.psz_string );
319     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
320     pQueue->push( CmdGenericPtr( pCmd ) );
321
322     return VLC_SUCCESS;
323 }
324
325
326 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
327                                vlc_value_t oldVal, vlc_value_t newVal,
328                                void *pParam )
329 {
330     (void)pObj; (void)pVariable; (void)oldVal;
331     VlcProc *pThis = (VlcProc*)pParam;
332     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
333
334     // Post a set preamp command
335     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
336                                               (newVal.f_float + 20.0) / 40.0 );
337     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
338     pQueue->push( CmdGenericPtr( pCmd ) );
339
340     return VLC_SUCCESS;
341 }
342
343
344 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
345                                 vlc_value_t oldVal, vlc_value_t newVal,
346                                 void *pParam )
347 {
348     (void)oldVal;
349     VlcProc *pThis = (VlcProc*)pParam;
350     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
351
352 #define ADD_CALLBACK_ENTRY( var, func, remove ) \
353     { \
354     if( strcmp( pVariable, var ) == 0 ) \
355     { \
356         string label = var; \
357         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal, \
358                                             &VlcProc::func, label ); \
359         if( pCmd ) \
360             pQueue->push( CmdGenericPtr( pCmd ), remove ); \
361         return VLC_SUCCESS; \
362     } \
363     }
364
365     ADD_CALLBACK_ENTRY( "volume", on_volume_changed, true )
366     ADD_CALLBACK_ENTRY( "mute", on_mute_changed, true )
367
368     ADD_CALLBACK_ENTRY( "bit-rate", on_bit_rate_changed, false )
369     ADD_CALLBACK_ENTRY( "sample-rate", on_sample_rate_changed, false )
370     ADD_CALLBACK_ENTRY( "can-record", on_can_record_changed, false )
371
372     ADD_CALLBACK_ENTRY( "random", on_random_changed, false )
373     ADD_CALLBACK_ENTRY( "loop", on_loop_changed, false )
374     ADD_CALLBACK_ENTRY( "repeat", on_repeat_changed, false )
375
376     ADD_CALLBACK_ENTRY( "audio-filter", on_audio_filter_changed, false )
377
378     ADD_CALLBACK_ENTRY( "intf-toggle-fscontrol", on_intf_show_changed, false )
379
380     ADD_CALLBACK_ENTRY( "mouse-moved", on_mouse_moved_changed, false )
381
382 #undef ADD_CALLBACK_ENTRY
383
384     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
385     return VLC_EGENERIC;
386 }
387
388
389 int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable,
390                                  vlc_value_t oldVal, vlc_value_t newVal,
391                                  void *pParam )
392 {
393     (void)oldVal;
394     VlcProc *pThis = (VlcProc*)pParam;
395     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
396
397     /**
398      * For intf-event, commands are labeled based on the value of newVal.
399      *
400      * For some values (e.g position), only keep the latest command
401      * when there are multiple pending commands (remove=true).
402      *
403      * for others, don't discard commands (remove=false)
404      **/
405     if( strcmp( pVariable, "intf-event" ) == 0 )
406     {
407         stringstream label;
408         bool b_remove;
409         switch( newVal.i_int )
410         {
411             case INPUT_EVENT_STATE:
412             case INPUT_EVENT_POSITION:
413             case INPUT_EVENT_RATE:
414             case INPUT_EVENT_ES:
415             case INPUT_EVENT_CHAPTER:
416             case INPUT_EVENT_RECORD:
417                 b_remove = true;
418                 break;
419             case INPUT_EVENT_VOUT:
420             case INPUT_EVENT_AOUT:
421             case INPUT_EVENT_DEAD:
422                 b_remove = false;
423                 break;
424             default:
425                 return VLC_SUCCESS;
426         }
427         label <<  pVariable << "_" << newVal.i_int;
428         CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal,
429                                             &VlcProc::on_intf_event_changed,
430                                             label.str() );
431         if( pCmd )
432             pQueue->push( CmdGenericPtr( pCmd ), b_remove );
433
434         return VLC_SUCCESS;
435     }
436
437     msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable );
438     return VLC_EGENERIC;
439 }
440
441
442 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
443 {
444     input_thread_t* pInput = (input_thread_t*) p_obj;
445
446     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
447
448     if( !getIntf()->p_sys->p_input )
449     {
450         msg_Dbg( getIntf(), "new input %p detected", pInput );
451
452         getIntf()->p_sys->p_input = pInput;
453         vlc_object_hold( pInput );
454
455         // update global variables pertaining to this input
456         update_current_input();
457
458         // ensure the playtree is also updated
459         // (highlights the new item to be played back)
460         getPlaytreeVar().onUpdateCurrent( true );
461     }
462
463     switch( newVal.i_int )
464     {
465         case INPUT_EVENT_STATE:
466         {
467             int state = var_GetInteger( pInput, "state" );
468             SET_BOOL( m_cVarStopped, false );
469             SET_BOOL( m_cVarPlaying, state != PAUSE_S );
470             SET_BOOL( m_cVarPaused, state == PAUSE_S );
471             break;
472         }
473
474         case INPUT_EVENT_POSITION:
475         {
476             float pos = var_GetFloat( pInput, "position" );
477             SET_STREAMTIME( m_cVarTime, pos, false );
478             SET_BOOL( m_cVarSeekable, pos != 0.0 );
479             break;
480         }
481
482         case INPUT_EVENT_RATE:
483         {
484             float rate = var_GetFloat( pInput, "rate" );
485             char* buffer;
486             if( asprintf( &buffer, "%.3g", rate ) != -1 )
487             {
488                 SET_TEXT( m_cVarSpeed, UString( getIntf(), buffer ) );
489                 free( buffer );
490             }
491             break;
492         }
493
494         case INPUT_EVENT_ES:
495         {
496             // Do we have audio
497             vlc_value_t audio_es;
498             var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
499                             &audio_es, NULL );
500             SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
501             break;
502         }
503
504         case INPUT_EVENT_VOUT:
505         {
506             vout_thread_t* pVout = input_GetVout( pInput );
507             SET_BOOL( m_cVarHasVout, pVout != NULL );
508             if( !pVout || pVout == m_pVout )
509             {
510                 // end of input or vout reuse (nothing to do)
511                 if( pVout )
512                     vlc_object_release( pVout );
513                 break;
514             }
515             if( m_pVout )
516             {
517                 // remove previous Vout callbacks
518                 var_DelCallback( m_pVout, "mouse-moved",
519                                  onGenericCallback, this );
520                 vlc_object_release( m_pVout );
521                 m_pVout = NULL;
522             }
523
524             // add new Vout callbackx
525             var_AddCallback( pVout, "mouse-moved",
526                              onGenericCallback, this );
527             m_pVout = pVout;
528             break;
529         }
530
531         case INPUT_EVENT_CHAPTER:
532         {
533             vlc_value_t chapters_count;
534             var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
535                         &chapters_count, NULL );
536             SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
537             break;
538         }
539
540         case INPUT_EVENT_RECORD:
541             SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
542             break;
543
544         case INPUT_EVENT_DEAD:
545             msg_Dbg( getIntf(), "end of input detected for %p", pInput );
546
547             var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
548             var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
549             var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
550             var_DelCallback( pInput, "can-record" , onGenericCallback, this );
551             vlc_object_release( pInput );
552             getIntf()->p_sys->p_input = NULL;
553             reset_input();
554             break;
555
556         default:
557             break;
558     }
559 }
560
561 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
562 {
563     (void)newVal;
564     input_thread_t* pInput = (input_thread_t*) p_obj;
565
566     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
567
568     int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
569     SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
570 }
571
572 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
573 {
574     (void)newVal;
575     input_thread_t* pInput = (input_thread_t*) p_obj;
576
577     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
578
579     int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
580     SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
581 }
582
583 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
584 {
585     (void)newVal;
586     input_thread_t* pInput = (input_thread_t*) p_obj;
587
588     assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
589
590     SET_BOOL( m_cVarRecordable, var_GetBool(  pInput, "can-record" ) );
591 }
592
593 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
594 {
595     (void)newVal;
596     playlist_t* pPlaylist = (playlist_t*) p_obj;
597
598     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
599 }
600
601 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
602 {
603     (void)newVal;
604     playlist_t* pPlaylist = (playlist_t*) p_obj;
605
606     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
607 }
608
609 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
610 {
611     (void)newVal;
612     playlist_t* pPlaylist = (playlist_t*) p_obj;
613
614     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
615 }
616
617 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
618 {
619     (void)p_obj; (void)newVal;
620     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
621
622     SET_VOLUME( m_cVarVolume, var_GetFloat( pPlaylist, "volume" ), false );
623 }
624
625 void VlcProc::on_mute_changed( vlc_object_t* p_obj, vlc_value_t newVal )
626 {
627     (void)p_obj;
628     SET_BOOL( m_cVarMute, newVal.b_bool );
629 }
630
631 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
632 {
633     (void)p_obj;
634     char *pFilters = newVal.psz_string;
635     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
636     SET_BOOL( m_cVarEqualizer, b_equalizer );
637 }
638
639 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
640 {
641     (void)p_obj; (void)newVal;
642     bool b_fullscreen = getFullscreenVar().get();
643
644     if( !b_fullscreen )
645     {
646         if( newVal.b_bool )
647         {
648             // Create a raise all command
649             CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
650                 getIntf()->p_sys->p_theme->getWindowManager() );
651
652             // Push the command in the asynchronous command queue
653             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
654             pQueue->push( CmdGenericPtr( pCmd ) );
655         }
656     }
657     else
658     {
659         VoutManager* pVoutManager =  VoutManager::instance( getIntf() );
660         FscWindow *pWin = pVoutManager->getFscWindow();
661         if( pWin )
662         {
663             bool b_visible = pWin->getVisibleVar().get();
664             AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
665
666             if( !b_visible )
667             {
668                CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
669                              getIntf()->p_sys->p_theme->getWindowManager(),
670                              *pWin );
671                pQueue->push( CmdGenericPtr( pCmd ) );
672             }
673             else
674             {
675                CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
676                               getIntf()->p_sys->p_theme->getWindowManager(),
677                               *pWin );
678                pQueue->push( CmdGenericPtr( pCmd ) );
679             }
680         }
681     }
682 }
683
684 void VlcProc::on_mouse_moved_changed( vlc_object_t* p_obj, vlc_value_t newVal )
685 {
686     (void)p_obj; (void)newVal;
687     FscWindow* pFscWindow = VoutManager::instance( getIntf() )->getFscWindow();
688     if( pFscWindow )
689         pFscWindow->onMouseMoved();
690 }
691
692 void VlcProc::reset_input()
693 {
694     SET_BOOL( m_cVarSeekable, false );
695     SET_BOOL( m_cVarRecordable, false );
696     SET_BOOL( m_cVarRecording, false );
697     SET_BOOL( m_cVarDvdActive, false );
698     SET_BOOL( m_cVarHasAudio, false );
699     SET_BOOL( m_cVarHasVout, false );
700     SET_BOOL( m_cVarStopped, true );
701     SET_BOOL( m_cVarPlaying, false );
702     SET_BOOL( m_cVarPaused, false );
703
704     SET_STREAMTIME( m_cVarTime, 0, false );
705     SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
706     SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
707     SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
708     SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
709
710     getPlaytreeVar().onUpdateCurrent( false );
711 }
712
713 void VlcProc::init_variables()
714 {
715     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
716
717     SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
718     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
719     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
720
721     SET_VOLUME( m_cVarVolume, var_GetFloat( pPlaylist, "volume" ), false );
722     SET_BOOL( m_cVarMute, var_GetBool( pPlaylist, "mute" ) );
723
724     SET_BOOL( m_cVarStopped, true );
725
726     init_equalizer();
727 }
728
729
730 void VlcProc::update_current_input()
731 {
732     input_thread_t* pInput = getIntf()->p_sys->p_input;
733     if( !pInput )
734         return;
735
736     input_item_t *pItem = input_GetItem( pInput );
737     if( pItem )
738     {
739         // Update short name (as defined by --input-title-format)
740         char *psz_fmt = var_InheritString( getIntf(), "input-title-format" );
741         char *psz_name = str_format_meta( pInput, psz_fmt );
742         SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
743         free( psz_fmt );
744         free( psz_name );
745
746         // Update local path (if possible) or full uri
747         char *psz_uri = input_item_GetURI( pItem );
748         char *psz_path = make_path( psz_uri );
749         char *psz_save = psz_path ? psz_path : psz_uri;
750         SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_save ) );
751         free( psz_path );
752         free( psz_uri );
753
754         // Update art uri
755         char *psz_art = input_item_GetArtURL( pItem );
756         SET_STRING( m_cVarStreamArt, string( psz_art ? psz_art : "" ) );
757         free( psz_art );
758     }
759 }
760
761 void VlcProc::init_equalizer()
762 {
763     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
764     audio_output_t* pAout = playlist_GetAout( pPlaylist );
765     if( pAout )
766     {
767         if( !var_Type( pAout, "equalizer-bands" ) )
768             var_Create( pAout, "equalizer-bands",
769                         VLC_VAR_STRING | VLC_VAR_DOINHERIT);
770         if( !var_Type( pAout, "equalizer-preamp" ) )
771             var_Create( pAout, "equalizer-preamp",
772                         VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
773
774         // New Aout (addCallbacks)
775         var_AddCallback( pAout, "audio-filter",
776                          onGenericCallback, this );
777         var_AddCallback( pAout, "equalizer-bands",
778                          onEqBandsChange, this );
779         var_AddCallback( pAout, "equalizer-preamp",
780                          onEqPreampChange, this );
781     }
782
783     // is equalizer enabled ?
784     char *pFilters = pAout ?
785                    var_GetNonEmptyString( pAout, "audio-filter" ) :
786                    var_InheritString( getIntf(), "audio-filter" );
787     bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
788     free( pFilters );
789     SET_BOOL( m_cVarEqualizer, b_equalizer );
790
791     // retrieve initial bands
792     char* bands = pAout ?
793                   var_GetString( pAout, "equalizer-bands" ) :
794                   var_InheritString( getIntf(), "equalizer-bands" );
795     if( bands )
796     {
797         m_varEqBands.set( bands );
798         free( bands );
799     }
800
801     // retrieve initial preamp
802     float preamp = pAout ?
803                    var_GetFloat( pAout, "equalizer-preamp" ) :
804                    var_InheritFloat( getIntf(), "equalizer-preamp" );
805     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)m_cVarEqPreamp.get();
806     pVarPreamp->set( (preamp + 20.0) / 40.0 );
807
808     if( pAout )
809         vlc_object_release( pAout);
810 }
811
812 void VlcProc::setFullscreenVar( bool b_fullscreen )
813 {
814     SET_BOOL( m_cVarFullscreen, b_fullscreen );
815 }
816
817 #undef  SET_BOOL
818 #undef  SET_STREAMTIME
819 #undef  SET_TEXT
820 #undef  SET_STRING
821 #undef  SET_VOLUME