skins2: fix memory leak (a malloc not paired with a free)
[vlc/solaris.git] / modules / gui / skins2 / src / vlcproc.cpp
blob208a56fc1972aa32e31bab6c407c14d4c2f5a4d2
1 /*****************************************************************************
2 * vlcproc.cpp
3 *****************************************************************************
4 * Copyright (C) 2003-2009 the VideoLAN team
5 * $Id$
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
9 * Erwan Tulou <erwan10@videolan.org>
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.
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.
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 *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include <vlc_common.h>
31 #include <vlc_aout.h>
32 #include <vlc_vout.h>
33 #include <vlc_playlist.h>
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 <sstream>
55 #include <assert.h>
57 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
59 if( pIntf->p_sys->p_vlcProc == NULL )
61 pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
64 return pIntf->p_sys->p_vlcProc;
68 void VlcProc::destroy( intf_thread_t *pIntf )
70 delete pIntf->p_sys->p_vlcProc;
71 pIntf->p_sys->p_vlcProc = NULL;
75 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
76 m_varEqBands( pIntf ), m_pVout( NULL ), m_pAout( NULL ),
77 m_bEqualizer_started( false ), m_cmdManage( this )
79 // Create a timer to poll the status of the vlc
80 OSFactory *pOsFactory = OSFactory::instance( pIntf );
81 m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
82 m_pTimer->start( 100, false );
84 // Create and register VLC variables
85 VarManager *pVarManager = VarManager::instance( getIntf() );
87 #define REGISTER_VAR( var, type, name ) \
88 var = VariablePtr( new type( getIntf() ) ); \
89 pVarManager->registerVar( var, name );
90 REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
91 REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
92 REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
93 REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
94 pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
95 "playtree.slider" );
96 pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
97 pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
99 REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
100 REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
101 REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
103 /* Input variables */
104 pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
105 REGISTER_VAR( m_cVarTime, StreamTime, "time" )
106 REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
107 REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
109 REGISTER_VAR( m_cVarRecordable, VarBoolImpl, "vlc.canRecord" )
110 REGISTER_VAR( m_cVarRecording, VarBoolImpl, "vlc.isRecording" )
112 /* Vout variables */
113 REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
114 REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
116 /* Aout variables */
117 REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
118 REGISTER_VAR( m_cVarVolume, Volume, "volume" )
119 REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
120 REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
121 REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
123 #undef REGISTER_VAR
124 m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
125 pVarManager->registerVar( m_cVarStreamName, "streamName" );
126 m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
127 pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
128 m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
129 pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
130 m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
131 pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
133 // Register the equalizer bands
134 for( int i = 0; i < EqualizerBands::kNbBands; i++)
136 stringstream ss;
137 ss << "equalizer.band(" << i << ")";
138 pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
141 // XXX WARNING XXX
142 // The object variable callbacks are called from other VLC threads,
143 // so they must put commands in the queue and NOT do anything else
144 // (X11 calls are not reentrant)
146 #define ADD_CALLBACK( p_object, var ) \
147 var_AddCallback( p_object, var, onGenericCallback, this );
149 ADD_CALLBACK( pIntf->p_sys->p_playlist, "volume-change" )
150 ADD_CALLBACK( pIntf->p_libvlc, "intf-show" )
152 ADD_CALLBACK( pIntf->p_sys->p_playlist, "item-current" )
153 ADD_CALLBACK( pIntf->p_sys->p_playlist, "random" )
154 ADD_CALLBACK( pIntf->p_sys->p_playlist, "loop" )
155 ADD_CALLBACK( pIntf->p_sys->p_playlist, "repeat" )
157 #undef ADD_CALLBACK
159 // Called when a playlist item is added
160 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-append",
161 onItemAppend, this );
162 // Called when a playlist item is deleted
163 // TODO: properly handle item-deleted
164 var_AddCallback( pIntf->p_sys->p_playlist, "playlist-item-deleted",
165 onItemDelete, this );
166 // Called when the current input changes
167 var_AddCallback( pIntf->p_sys->p_playlist, "input-current",
168 onInputNew, this );
169 // Called when a playlist item changed
170 var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
171 onItemChange, this );
172 // Called when our skins2 demux wants us to load a new skin
173 var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
175 // Called when we have an interaction dialog to display
176 var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
177 var_AddCallback( pIntf, "interaction", onInteraction, this );
178 interaction_Register( pIntf );
180 // initialize variables refering to liblvc and playlist objects
181 init_variables();
185 VlcProc::~VlcProc()
187 m_pTimer->stop();
188 delete( m_pTimer );
190 if( m_pAout )
192 vlc_object_release( m_pAout );
193 m_pAout = NULL;
195 if( m_pVout )
197 vlc_object_release( m_pVout );
198 m_pVout = NULL;
201 interaction_Unregister( getIntf() );
203 var_DelCallback( getIntf()->p_sys->p_playlist, "volume-change",
204 onGenericCallback, this );
205 var_DelCallback( getIntf()->p_libvlc, "intf-show",
206 onGenericCallback, this );
208 var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
209 onGenericCallback, this );
210 var_DelCallback( getIntf()->p_sys->p_playlist, "random",
211 onGenericCallback, this );
212 var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
213 onGenericCallback, this );
214 var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
215 onGenericCallback, this );
217 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
218 onItemAppend, this );
219 var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-deleted",
220 onItemDelete, this );
221 var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
222 onInputNew, this );
223 var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
224 onItemChange, this );
225 var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
226 var_DelCallback( getIntf(), "interaction", onInteraction, this );
229 void VlcProc::manage()
231 // Did the user request to quit vlc ?
232 if( !vlc_object_alive( getIntf() ) )
234 // Get the instance of OSFactory
235 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
237 // Exit the main OS loop
238 pOsFactory->getOSLoop()->exit();
240 return;
244 void VlcProc::CmdManage::execute()
246 // Just forward to VlcProc
247 m_pParent->manage();
251 int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
252 vlc_value_t oldval, vlc_value_t newval, void *pParam )
254 VlcProc *pThis = (VlcProc*)pParam;
255 input_thread_t *pInput = static_cast<input_thread_t*>(newval.p_address);
257 var_AddCallback( pInput, "intf-event", onGenericCallback, 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 );
262 return VLC_SUCCESS;
266 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
267 vlc_value_t oldval, vlc_value_t newval,
268 void *pParam )
270 VlcProc *pThis = (VlcProc*)pParam;
271 input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
273 // Create a playtree notify command
274 CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
275 p_item );
277 // Push the command in the asynchronous command queue
278 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
279 pQueue->push( CmdGenericPtr( pCmdTree ), true );
281 return VLC_SUCCESS;
284 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
285 vlc_value_t oldVal, vlc_value_t newVal,
286 void *pParam )
288 VlcProc *pThis = (VlcProc*)pParam;
290 playlist_add_t *p_add = static_cast<playlist_add_t*>(newVal.p_address);
292 CmdGenericPtr ptrTree;
293 CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
294 p_add );
295 ptrTree = CmdGenericPtr( pCmdTree );
297 // Push the command in the asynchronous command queue
298 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
299 pQueue->push( ptrTree , false );
301 return VLC_SUCCESS;
304 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
305 vlc_value_t oldVal, vlc_value_t newVal,
306 void *pParam )
308 VlcProc *pThis = (VlcProc*)pParam;
310 int i_id = newVal.i_int;
312 CmdGenericPtr ptrTree;
313 CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
314 i_id);
315 ptrTree = CmdGenericPtr( pCmdTree );
317 // Push the command in the asynchronous command queue
318 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
319 pQueue->push( ptrTree , false );
321 return VLC_SUCCESS;
325 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
326 vlc_value_t oldVal, vlc_value_t newVal,
327 void *pParam )
329 VlcProc *pThis = (VlcProc*)pParam;
331 // Create a playlist notify command
332 CmdChangeSkin *pCmd =
333 new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
335 // Push the command in the asynchronous command queue
336 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
337 pQueue->push( CmdGenericPtr( pCmd ) );
339 return VLC_SUCCESS;
342 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
343 vlc_value_t oldVal, vlc_value_t newVal,
344 void *pParam )
346 VlcProc *pThis = (VlcProc*)pParam;
347 interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
349 CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
350 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
351 pQueue->push( CmdGenericPtr( pCmd ) );
352 return VLC_SUCCESS;
355 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
356 vlc_value_t oldVal, vlc_value_t newVal,
357 void *pParam )
359 VlcProc *pThis = (VlcProc*)pParam;
361 // Post a set equalizer bands command
362 CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
363 pThis->m_varEqBands,
364 newVal.psz_string );
365 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
366 pQueue->push( CmdGenericPtr( pCmd ) );
368 return VLC_SUCCESS;
372 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
373 vlc_value_t oldVal, vlc_value_t newVal,
374 void *pParam )
376 VlcProc *pThis = (VlcProc*)pParam;
377 EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
379 // Post a set preamp command
380 CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
381 (newVal.f_float + 20.0) / 40.0 );
382 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
383 pQueue->push( CmdGenericPtr( pCmd ) );
385 return VLC_SUCCESS;
389 int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
390 vlc_value_t oldVal, vlc_value_t newVal,
391 void *pParam )
393 VlcProc *pThis = (VlcProc*)pParam;
394 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
396 CmdGeneric *pCmd = NULL;
398 #define ADD_CALLBACK_ENTRY( var, label ) \
400 if( strcmp( pVariable, var ) == 0 ) \
401 pCmd = new Cmd_##label( pThis->getIntf(), pObj, newVal ); \
404 ADD_CALLBACK_ENTRY( "item-current", item_current_changed )
405 ADD_CALLBACK_ENTRY( "volume-change", volume_changed )
407 ADD_CALLBACK_ENTRY( "intf-event", intf_event_changed )
408 ADD_CALLBACK_ENTRY( "bit-rate", bit_rate_changed )
409 ADD_CALLBACK_ENTRY( "sample-rate", sample_rate_changed )
410 ADD_CALLBACK_ENTRY( "can-record", can_record_changed )
412 ADD_CALLBACK_ENTRY( "random", random_changed )
413 ADD_CALLBACK_ENTRY( "loop", loop_changed )
414 ADD_CALLBACK_ENTRY( "repeat", repeat_changed )
416 ADD_CALLBACK_ENTRY( "audio-filter", audio_filter_changed )
418 ADD_CALLBACK_ENTRY( "intf-show", intf_show_changed )
420 #undef ADD_CALLBACK_ENTRY
422 if( pCmd )
423 pQueue->push( CmdGenericPtr( pCmd ), false );
424 else
425 msg_Err( pObj, "no Callback entry provided for %s", pVariable );
427 return VLC_SUCCESS;
430 #define SET_BOOL(m,v) ((VarBoolImpl*)(m).get())->set(v)
431 #define SET_STREAMTIME(m,v,b) ((StreamTime*)(m).get())->set(v,b)
432 #define SET_TEXT(m,v) ((VarText*)(m).get())->set(v)
433 #define SET_VOLUME(m,v,b) ((Volume*)(m).get())->set(v,b)
435 void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
437 input_item_t *p_item = static_cast<input_item_t*>(newVal.p_address);
439 // Update short name
440 char *psz_name = input_item_GetName( p_item );
441 SET_TEXT( m_cVarStreamName, UString( getIntf(), psz_name ) );
442 free( psz_name );
444 // Update full uri
445 char *psz_uri = input_item_GetURI( p_item );
446 SET_TEXT( m_cVarStreamURI, UString( getIntf(), psz_uri ) );
447 free( psz_uri );
449 // Update playtree
450 getPlaytreeVar().onUpdateCurrent( true );
453 void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
455 input_thread_t* pInput = (input_thread_t*) p_obj;
457 assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
459 if( !getIntf()->p_sys->p_input )
461 msg_Dbg( getIntf(), "new input %p detected", pInput );
463 getIntf()->p_sys->p_input = pInput;
464 vlc_object_hold( pInput );
467 switch( newVal.i_int )
469 case INPUT_EVENT_STATE:
471 int state = var_GetInteger( pInput, "state" );
472 SET_BOOL( m_cVarStopped, false );
473 SET_BOOL( m_cVarPlaying, state != PAUSE_S );
474 SET_BOOL( m_cVarPaused, state == PAUSE_S );
475 break;
478 case INPUT_EVENT_POSITION:
480 float pos = var_GetFloat( pInput, "position" );
481 SET_STREAMTIME( m_cVarTime, pos, false );
482 SET_BOOL( m_cVarSeekable, pos != 0.0 );
483 break;
486 case INPUT_EVENT_ES:
488 // Do we have audio
489 vlc_value_t audio_es;
490 var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
491 &audio_es, NULL );
492 SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
493 break;
496 case INPUT_EVENT_VOUT:
498 vout_thread_t* pVout = input_GetVout( pInput );
499 SET_BOOL( m_cVarHasVout, pVout != NULL );
500 if( pVout )
502 SET_BOOL( m_cVarFullscreen,
503 var_GetBool( pVout, "fullscreen" ) );
504 vlc_object_release( pVout );
506 break;
509 case INPUT_EVENT_AOUT:
511 aout_instance_t* pAout = input_GetAout( pInput );
513 // end of input or aout reuse (nothing to do)
514 if( !pAout || pAout == m_pAout )
516 if( pAout )
517 vlc_object_release( pAout );
518 break;
521 // remove previous Aout if any
522 if( m_pAout )
524 var_DelCallback( m_pAout, "audio-filter",
525 onGenericCallback, this );
526 if( m_bEqualizer_started )
528 var_DelCallback( m_pAout, "equalizer-bands",
529 onEqBandsChange, this );
530 var_DelCallback( m_pAout, "equalizer-preamp",
531 onEqPreampChange, this );
533 vlc_object_release( m_pAout );
534 m_pAout = NULL;
535 m_bEqualizer_started = false;
538 // New Aout (addCallbacks)
539 var_AddCallback( pAout, "audio-filter", onGenericCallback, this );
541 char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
542 bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
543 free( pFilters );
544 SET_BOOL( m_cVarEqualizer, b_equalizer );
545 if( b_equalizer )
547 var_AddCallback( pAout, "equalizer-bands",
548 onEqBandsChange, this );
549 var_AddCallback( pAout, "equalizer-preamp",
550 onEqPreampChange, this );
551 m_bEqualizer_started = true;
553 m_pAout = pAout;
554 break;
557 case INPUT_EVENT_CHAPTER:
559 vlc_value_t chapters_count;
560 var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
561 &chapters_count, NULL );
562 SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
563 break;
566 case INPUT_EVENT_RECORD:
567 SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
568 break;
570 case INPUT_EVENT_DEAD:
571 msg_Dbg( getIntf(), "end of input detected for %p", pInput );
573 var_DelCallback( pInput, "intf-event", onGenericCallback, this );
574 var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
575 var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
576 var_DelCallback( pInput, "can-record" , onGenericCallback, this );
577 vlc_object_release( pInput );
578 getIntf()->p_sys->p_input = NULL;
579 reset_input();
580 break;
582 default:
583 break;
587 void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
589 input_thread_t* pInput = (input_thread_t*) p_obj;
591 assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
593 int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
594 SET_TEXT( m_cVarStreamBitRate, UString::fromInt( getIntf(), bitrate ) );
597 void VlcProc::on_sample_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
599 input_thread_t* pInput = (input_thread_t*) p_obj;
601 assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
603 int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
604 SET_TEXT( m_cVarStreamSampleRate, UString::fromInt(getIntf(),sampleRate) );
607 void VlcProc::on_can_record_changed( vlc_object_t* p_obj, vlc_value_t newVal )
609 input_thread_t* pInput = (input_thread_t*) p_obj;
611 assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );
613 SET_BOOL( m_cVarRecordable, var_GetBool( pInput, "can-record" ) );
616 void VlcProc::on_random_changed( vlc_object_t* p_obj, vlc_value_t newVal )
618 playlist_t* pPlaylist = (playlist_t*) p_obj;
620 SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
623 void VlcProc::on_loop_changed( vlc_object_t* p_obj, vlc_value_t newVal )
625 playlist_t* pPlaylist = (playlist_t*) p_obj;
627 SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
630 void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
632 playlist_t* pPlaylist = (playlist_t*) p_obj;
634 SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
637 void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
639 (void)p_obj; (void)newVal;
640 playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
642 audio_volume_t volume;
643 aout_VolumeGet( pPlaylist, &volume );
644 SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
645 SET_BOOL( m_cVarMute, volume == 0 );
648 void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
650 aout_instance_t* pAout = (aout_instance_t*) p_obj;
652 char *pFilters = newVal.psz_string;
654 bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
655 SET_BOOL( m_cVarEqualizer, b_equalizer );
656 if( b_equalizer && !m_bEqualizer_started )
658 var_AddCallback( pAout, "equalizer-bands", onEqBandsChange, this );
659 var_AddCallback( pAout, "equalizer-preamp", onEqPreampChange, this );
660 m_bEqualizer_started = true;
664 void VlcProc::on_intf_show_changed( vlc_object_t* p_obj, vlc_value_t newVal )
666 (void)p_obj;
667 bool b_fullscreen = getFullscreenVar().get();
669 if( !b_fullscreen )
671 if( newVal.b_bool )
673 // Create a raise all command
674 CmdRaiseAll *pCmd = new CmdRaiseAll( getIntf(),
675 getIntf()->p_sys->p_theme->getWindowManager() );
677 // Push the command in the asynchronous command queue
678 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
679 pQueue->push( CmdGenericPtr( pCmd ) );
682 else
684 Theme* pTheme = getIntf()->p_sys->p_theme;
685 TopWindow *pWin = pTheme->getWindowById( "fullscreenController" );
686 if( pWin )
688 bool b_visible = pWin->getVisibleVar().get();
689 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
691 if( !b_visible )
693 CmdShowWindow* pCmd = new CmdShowWindow( getIntf(),
694 getIntf()->p_sys->p_theme->getWindowManager(),
695 *pWin );
696 pQueue->push( CmdGenericPtr( pCmd ) );
698 else
700 CmdHideWindow* pCmd = new CmdHideWindow( getIntf(),
701 getIntf()->p_sys->p_theme->getWindowManager(),
702 *pWin );
703 pQueue->push( CmdGenericPtr( pCmd ) );
709 void VlcProc::reset_input()
711 SET_BOOL( m_cVarSeekable, false );
712 SET_BOOL( m_cVarRecordable, false );
713 SET_BOOL( m_cVarRecording, false );
714 SET_BOOL( m_cVarDvdActive, false );
715 SET_BOOL( m_cVarFullscreen, false );
716 SET_BOOL( m_cVarHasAudio, false );
717 SET_BOOL( m_cVarHasVout, false );
718 SET_BOOL( m_cVarStopped, true );
719 SET_BOOL( m_cVarPlaying, false );
720 SET_BOOL( m_cVarPaused, false );
722 SET_STREAMTIME( m_cVarTime, 0, false );
723 SET_TEXT( m_cVarStreamName, UString( getIntf(), "") );
724 SET_TEXT( m_cVarStreamURI, UString( getIntf(), "") );
725 SET_TEXT( m_cVarStreamBitRate, UString( getIntf(), "") );
726 SET_TEXT( m_cVarStreamSampleRate, UString( getIntf(), "") );
728 getPlaytreeVar().onUpdateCurrent( false );
731 void VlcProc::init_variables()
733 playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
735 SET_BOOL( m_cVarRandom, var_GetBool( pPlaylist, "random" ) );
736 SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
737 SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
739 audio_volume_t volume;
740 aout_VolumeGet( pPlaylist, &volume );
741 SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
742 SET_BOOL( m_cVarMute, volume == 0 );
744 update_equalizer();
747 void VlcProc::update_equalizer()
750 char *pFilters;
751 if( m_pAout )
752 pFilters = var_GetNonEmptyString( m_pAout, "audio-filter" );
753 else
754 pFilters = var_InheritString( getIntf(), "audio-filter" );
756 bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
757 free( pFilters );
759 SET_BOOL( m_cVarEqualizer, b_equalizer );
762 void VlcProc::setFullscreenVar( bool b_fullscreen )
764 SET_BOOL( m_cVarFullscreen, b_fullscreen );
767 #undef SET_BOOL
768 #undef SET_STREAMTIME
769 #undef SET_TEXT
770 #undef SET_VOLUME