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