]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
649f47f27eb1c375c51971641e80333f1b90ece5
[vlc] / modules / gui / skins2 / src / vlcproc.cpp
1 /*****************************************************************************
2  * vlcproc.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teuli�e <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <vlc/aout.h>
26 #include <vlc/vout.h>
27 #include <aout_internal.h>
28
29 #include "vlcproc.hpp"
30 #include "os_factory.hpp"
31 #include "os_timer.hpp"
32 #include "var_manager.hpp"
33 #include "theme.hpp"
34 #include "window_manager.hpp"
35 #include "../commands/async_queue.hpp"
36 #include "../commands/cmd_change_skin.hpp"
37 #include "../commands/cmd_show_window.hpp"
38 #include "../commands/cmd_quit.hpp"
39 #include "../commands/cmd_resize.hpp"
40 #include "../commands/cmd_vars.hpp"
41 #include "../commands/cmd_dialogs.hpp"
42 #include "../utils/var_bool.hpp"
43 #include <sstream>
44
45
46 VlcProc *VlcProc::instance( intf_thread_t *pIntf )
47 {
48     if( pIntf->p_sys->p_vlcProc == NULL )
49     {
50         pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
51     }
52
53     return pIntf->p_sys->p_vlcProc;
54 }
55
56
57 void VlcProc::destroy( intf_thread_t *pIntf )
58 {
59     if( pIntf->p_sys->p_vlcProc )
60     {
61         delete pIntf->p_sys->p_vlcProc;
62         pIntf->p_sys->p_vlcProc = NULL;
63     }
64 }
65
66
67 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
68     m_varVoutSize( pIntf ), m_varEqBands( pIntf ),
69     m_pVout( NULL ), m_pAout( NULL ), m_cmdManage( this )
70 {
71     // Create a timer to poll the status of the vlc
72     OSFactory *pOsFactory = OSFactory::instance( pIntf );
73     m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
74     m_pTimer->start( 100, false );
75
76     // Create and register VLC variables
77     VarManager *pVarManager = VarManager::instance( getIntf() );
78
79 #define REGISTER_VAR( var, type, name ) \
80     var = VariablePtr( new type( getIntf() ) ); \
81     pVarManager->registerVar( var, name );
82
83     /* Playlist variables */
84     REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
85     pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
86                               "playlist.slider" );
87     REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
88     REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
89     REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
90     REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
91     pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
92                               "playtree.slider" );
93     pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
94     pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
95
96     REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
97     REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
98     REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
99
100     /* Input variables */
101     pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
102     REGISTER_VAR( m_cVarTime, StreamTime, "time" )
103     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
104     REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
105
106     /* Vout variables */
107     REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
108     REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
109
110     /* Aout variables */
111     REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
112     REGISTER_VAR( m_cVarVolume, Volume, "volume" )
113     REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
114     REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
115     REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )
116
117 #undef REGISTER_VAR
118     m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
119     pVarManager->registerVar( m_cVarStreamName, "streamName" );
120     m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
121     pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
122     m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
123     pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
124     m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
125     pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
126
127     // Register the equalizer bands
128     for( int i = 0; i < EqualizerBands::kNbBands; i++)
129     {
130         stringstream ss;
131         ss << "equalizer.band(" << i << ")";
132         pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
133     }
134
135     // XXX WARNING XXX
136     // The object variable callbacks are called from other VLC threads,
137     // so they must put commands in the queue and NOT do anything else
138     // (X11 calls are not reentrant)
139
140     // Called when the playlist changes
141     var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
142                      onIntfChange, this );
143     // Called when a playlist item is added
144     var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
145                      onItemAppend, this );
146     // Called when a playlist item is deleted
147     // TODO: properly handle item-deleted
148     var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
149                      onItemDelete, this );
150     // Called when the "interface shower" wants us to show the skin
151     var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
152                      onIntfShow, this );
153     // Called when the current played item changes
154     var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
155                      onPlaylistChange, this );
156     // Called when a playlist item changed
157     var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
158                      onItemChange, this );
159     // Called when our skins2 demux wants us to load a new skin
160     var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
161
162     // Called when we have an interaction dialog to display
163     var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
164     var_AddCallback( pIntf, "interaction", onInteraction, this );
165     pIntf->b_interaction = VLC_TRUE;
166
167     // Callbacks for vout requests
168     getIntf()->pf_request_window = &getWindow;
169     getIntf()->pf_release_window = &releaseWindow;
170     getIntf()->pf_control_window = &controlWindow;
171
172     getIntf()->p_sys->p_input = NULL;
173 }
174
175
176 VlcProc::~VlcProc()
177 {
178     m_pTimer->stop();
179     delete( m_pTimer );
180     if( getIntf()->p_sys->p_input )
181     {
182         vlc_object_release( getIntf()->p_sys->p_input );
183     }
184
185     // Callbacks for vout requests
186     getIntf()->pf_request_window = NULL;
187     getIntf()->pf_release_window = NULL;
188     getIntf()->pf_control_window = NULL;
189
190     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
191                      onIntfChange, this );
192     var_DelCallback( getIntf()->p_sys->p_playlist, "item-append",
193                      onItemAppend, this );
194     var_DelCallback( getIntf()->p_sys->p_playlist, "item-deleted",
195                      onItemDelete, this );
196     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
197                      onIntfShow, this );
198     var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
199                      onPlaylistChange, this );
200     var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
201                      onItemChange, this );
202     var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
203 }
204
205
206 void VlcProc::registerVoutWindow( void *pVoutWindow )
207 {
208     m_handleSet.insert( pVoutWindow );
209     // Reparent the vout window
210     if( m_pVout )
211     {
212         if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
213             vout_Control( m_pVout, VOUT_CLOSE );
214     }
215 }
216
217
218 void VlcProc::unregisterVoutWindow( void *pVoutWindow )
219 {
220     m_handleSet.erase( pVoutWindow );
221 }
222
223
224 void VlcProc::dropVout()
225 {
226     if( m_pVout )
227     {
228         if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
229             vout_Control( m_pVout, VOUT_CLOSE );
230         m_pVout = NULL;
231     }
232 }
233
234
235 void VlcProc::manage()
236 {
237     // Did the user request to quit vlc ?
238     if( getIntf()->b_die || getIntf()->p_vlc->b_die )
239     {
240         CmdQuit *pCmd = new CmdQuit( getIntf() );
241         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
242         pQueue->push( CmdGenericPtr( pCmd ) );
243     }
244
245     refreshPlaylist();
246     refreshAudio();
247     refreshInput();
248 }
249 void VlcProc::CmdManage::execute()
250 {
251     // Just forward to VlcProc
252     m_pParent->manage();
253 }
254
255 void VlcProc::refreshAudio()
256 {
257     char *pFilters = NULL;
258
259     // Check if the audio output has changed
260     aout_instance_t *pAout = (aout_instance_t *)vlc_object_find( getIntf(),
261             VLC_OBJECT_AOUT, FIND_ANYWHERE );
262     if( pAout )
263     {
264         if( pAout != m_pAout )
265         {
266             // Register the equalizer callbacks
267             if( !var_AddCallback( pAout, "equalizer-bands",
268                                   onEqBandsChange, this ) &&
269                 !var_AddCallback( pAout, "equalizer-preamp",
270                                   onEqPreampChange, this ) )
271             {
272                 m_pAout = pAout;
273                 //char * psz_bands = var_GetString( p_aout, "equalizer-bands" );
274             }
275         }
276         // Get the audio filters
277         pFilters = var_GetString( pAout, "audio-filter" );
278         vlc_object_release( pAout );
279     }
280     else
281     {
282         // Get the audio filters
283         pFilters = config_GetPsz( getIntf(), "audio-filter" );
284     }
285
286     // Refresh sound volume
287     audio_volume_t volume;
288     aout_VolumeGet( getIntf(), &volume );
289     Volume *pVolume = (Volume*)m_cVarVolume.get();
290     pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX );
291
292     // Set the mute variable
293     VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
294     pVarMute->set( volume == 0 );
295
296     // Refresh the equalizer variable
297     VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
298     pVarEqualizer->set( pFilters && strstr( pFilters, "equalizer" ) );
299 }
300
301 void VlcProc::refreshPlaylist()
302 {
303     // Get the status of the playlist
304     VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
305     VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
306     VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
307     playlist_status_t status =
308              getIntf()->p_sys->p_playlist->status.i_status;
309
310     pVarPlaying->set( status == PLAYLIST_RUNNING );
311     pVarStopped->set( status == PLAYLIST_STOPPED );
312     pVarPaused->set( status == PLAYLIST_PAUSED );
313
314     // Refresh the random variable
315     VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
316     vlc_value_t val;
317     var_Get( getIntf()->p_sys->p_playlist, "random", &val );
318     pVarRandom->set( val.b_bool != 0 );
319
320     // Refresh the loop variable
321     VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
322     var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
323     pVarLoop->set( val.b_bool != 0 );
324
325     // Refresh the repeat variable
326     VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
327     var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
328     pVarRepeat->set( val.b_bool != 0 );
329 }
330
331 void VlcProc::refreshInput()
332 {
333     StreamTime *pTime = (StreamTime*)m_cVarTime.get();
334     VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
335     VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
336     VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
337     VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get();
338     VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get();
339     VarText *pSampleRate = (VarText*)m_cVarStreamSampleRate.get();
340     VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
341
342     // Update the input
343     if( getIntf()->p_sys->p_input == NULL )
344     {
345         getIntf()->p_sys->p_input = getIntf()->p_sys->p_playlist->p_input;
346         if( getIntf()->p_sys->p_input )
347             vlc_object_yield( getIntf()->p_sys->p_input );
348     }
349     else if( getIntf()->p_sys->p_input->b_dead )
350     {
351         vlc_object_release( getIntf()->p_sys->p_input );
352         getIntf()->p_sys->p_input = NULL;
353     }
354
355     input_thread_t *pInput = getIntf()->p_sys->p_input;
356
357     if( pInput && !pInput->b_die )
358     {
359         // Refresh time variables
360         vlc_value_t pos;
361         var_Get( pInput, "position", &pos );
362         pTime->set( pos.f_float, false );
363         pVarSeekable->set( pos.f_float != 0.0 );
364
365         // Refresh DVD detection
366         vlc_value_t chapters_count;
367         var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
368                         &chapters_count, NULL );
369         pVarDvdActive->set( chapters_count.i_int > 0 );
370
371         // Get the input bitrate
372         int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
373         pBitrate->set( UString::fromInt( getIntf(), bitrate ) );
374
375         // Get the audio sample rate
376         int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
377         pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );
378
379         // Do we have audio
380         vlc_value_t audio_es;
381         var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
382                         &audio_es, NULL );
383         pVarHasAudio->set( audio_es.i_int > 0 );
384
385         // Refresh fullscreen status
386         vout_thread_t *pVout = (vout_thread_t *)vlc_object_find( pInput,
387                                      VLC_OBJECT_VOUT, FIND_CHILD );
388         pVarHasVout->set( pVout != NULL );
389         if( pVout )
390         {
391             pVarFullscreen->set( pVout->b_fullscreen );
392             vlc_object_release( pVout );
393         }
394     }
395     else
396     {
397         pVarSeekable->set( false );
398         pVarDvdActive->set( false );
399         pTime->set( 0, false );
400         pVarFullscreen->set( false );
401         pVarHasAudio->set( false );
402         pVarHasVout->set( false );
403     }
404 }
405
406 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
407                            vlc_value_t oldVal, vlc_value_t newVal,
408                            void *pParam )
409 {
410     VlcProc *pThis = (VlcProc*)pParam;
411
412     // Update the stream variable
413     playlist_t *p_playlist = (playlist_t*)pObj;
414     pThis->updateStreamName(p_playlist);
415
416     // Create a playlist notify command (for old style playlist)
417     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
418     // Create a playtree notify command (for new style playtree)
419     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
420
421     // Push the command in the asynchronous command queue
422     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
423     pQueue->push( CmdGenericPtr( pCmd ) );
424     pQueue->push( CmdGenericPtr( pCmdTree ) );
425
426     return VLC_SUCCESS;
427 }
428
429
430 int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
431                          vlc_value_t oldVal, vlc_value_t newVal,
432                          void *pParam )
433 {
434     if (newVal.i_int)
435     {
436         VlcProc *pThis = (VlcProc*)pParam;
437
438         // Create a raise all command
439         CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
440             pThis->getIntf()->p_sys->p_theme->getWindowManager() );
441
442         // Push the command in the asynchronous command queue
443         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
444         pQueue->push( CmdGenericPtr( pCmd ) );
445     }
446
447     return VLC_SUCCESS;
448 }
449
450
451 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
452                            vlc_value_t oldVal, vlc_value_t newVal,
453                            void *pParam )
454 {
455     VlcProc *pThis = (VlcProc*)pParam;
456
457     // Update the stream variable
458     playlist_t *p_playlist = (playlist_t*)pObj;
459     pThis->updateStreamName(p_playlist);
460
461     // Create a playlist notify command
462     // TODO: selective update
463     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
464     // Create a playtree notify command
465     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
466                                                          newVal.i_int );
467
468     // Push the command in the asynchronous command queue
469     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
470     pQueue->push( CmdGenericPtr( pCmd ) );
471     pQueue->push( CmdGenericPtr( pCmdTree ), true );
472
473     return VLC_SUCCESS;
474 }
475
476 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
477                            vlc_value_t oldVal, vlc_value_t newVal,
478                            void *pParam )
479 {
480     VlcProc *pThis = (VlcProc*)pParam;
481
482     playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(
483                                                 playlist_add_t ) ) ;
484
485     memcpy( p_add, newVal.p_address, sizeof( playlist_add_t ) ) ;
486
487     CmdGenericPtr ptrTree;
488     CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
489                                                              p_add );
490     ptrTree = CmdGenericPtr( pCmdTree );
491
492     // Create a playlist notify command (for old style playlist)
493     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
494
495     // Push the command in the asynchronous command queue
496     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
497     pQueue->push( CmdGenericPtr( pCmd ) );
498     pQueue->push( ptrTree , false );
499
500     return VLC_SUCCESS;
501 }
502
503 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
504                            vlc_value_t oldVal, vlc_value_t newVal,
505                            void *pParam )
506 {
507     VlcProc *pThis = (VlcProc*)pParam;
508
509     int i_id = newVal.i_int;
510
511     CmdGenericPtr ptrTree;
512     CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
513                                                          i_id);
514     ptrTree = CmdGenericPtr( pCmdTree );
515
516     // Create a playlist notify command (for old style playlist)
517     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
518
519     // Push the command in the asynchronous command queue
520     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
521     pQueue->push( CmdGenericPtr( pCmd ) );
522     pQueue->push( ptrTree , false );
523
524     return VLC_SUCCESS;
525 }
526
527
528
529
530 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
531                                vlc_value_t oldVal, vlc_value_t newVal,
532                                void *pParam )
533 {
534     VlcProc *pThis = (VlcProc*)pParam;
535
536     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
537
538     // Update the stream variable
539     playlist_t *p_playlist = (playlist_t*)pObj;
540     pThis->updateStreamName(p_playlist);
541
542     // Create a playlist notify command (old style playlist)
543     // TODO: selective update
544     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
545     pQueue->push( CmdGenericPtr( pCmd ) );
546     // Create two playtree notify commands: one for old item, one for new
547     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
548                                                          oldVal.i_int );
549     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
550     pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), newVal.i_int );
551     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
552
553     return VLC_SUCCESS;
554 }
555
556
557 int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
558                            vlc_value_t oldVal, vlc_value_t newVal,
559                            void *pParam )
560 {
561     VlcProc *pThis = (VlcProc*)pParam;
562
563     // Create a playlist notify command
564     CmdChangeSkin *pCmd =
565         new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
566
567     // Push the command in the asynchronous command queue
568     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
569     pQueue->push( CmdGenericPtr( pCmd ) );
570
571     return VLC_SUCCESS;
572 }
573
574 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
575                             vlc_value_t oldVal, vlc_value_t newVal,
576                             void *pParam )
577 {
578     VlcProc *pThis = (VlcProc*)pParam;
579     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
580
581     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
582     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
583     pQueue->push( CmdGenericPtr( pCmd ) );
584     return VLC_SUCCESS;
585 }
586
587
588 void VlcProc::updateStreamName( playlist_t *p_playlist )
589 {
590     if( p_playlist && p_playlist->p_input )
591     {
592         // Get playlist item information
593         input_item_t *pItem = p_playlist->p_input->input.p_item;
594
595         VarText &rStreamName = getStreamNameVar();
596         VarText &rStreamURI = getStreamURIVar();
597         // XXX: we should not need to access p_input->psz_source directly, a
598         // getter should be provided by VLC core
599         string name = pItem->psz_name;
600         // XXX: This should be done in VLC core, not here...
601         // Remove path information if any
602         OSFactory *pFactory = OSFactory::instance( getIntf() );
603         string::size_type pos = name.rfind( pFactory->getDirSeparator() );
604         if( pos != string::npos )
605         {
606             name = name.substr( pos + 1, name.size() - pos + 1 );
607         }
608         UString srcName( getIntf(), name.c_str() );
609         UString srcURI( getIntf(), pItem->psz_uri );
610
611        // Create commands to update the stream variables
612         CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
613         CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
614         // Push the commands in the asynchronous command queue
615         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
616         pQueue->push( CmdGenericPtr( pCmd1 ), false );
617         pQueue->push( CmdGenericPtr( pCmd2 ), false );
618     }
619 }
620
621
622 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
623                           int *pXHint, int *pYHint,
624                           unsigned int *pWidthHint,
625                           unsigned int *pHeightHint )
626 {
627     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
628     if( pThis->m_handleSet.empty() )
629     {
630         return NULL;
631     }
632     else
633     {
634         pThis->m_pVout = pVout;
635         // Get the window handle
636         void *pWindow = *pThis->m_handleSet.begin();
637         // Post a resize vout command
638         CmdResizeVout *pCmd = new CmdResizeVout( pThis->getIntf(), pWindow,
639                                                  *pWidthHint, *pHeightHint );
640         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
641         pQueue->push( CmdGenericPtr( pCmd ) );
642         return pWindow;
643     }
644 }
645
646
647 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
648 {
649     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
650     pThis->m_pVout = NULL;
651 }
652
653
654 int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
655                             int query, va_list args )
656 {
657     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
658
659     switch( query )
660     {
661         case VOUT_SET_SIZE:
662         {
663             if( pThis->m_pVout )
664             {
665                 unsigned int i_width  = va_arg( args, unsigned int );
666                 unsigned int i_height = va_arg( args, unsigned int );
667                 if( !i_width ) i_width = pThis->m_pVout->i_window_width;
668                 if( !i_height ) i_height = pThis->m_pVout->i_window_height;
669
670                 // Post a resize vout command
671                 CmdResizeVout *pCmd =
672                     new CmdResizeVout( pThis->getIntf(), pWindow,
673                                        i_width, i_height );
674                 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
675                 pQueue->push( CmdGenericPtr( pCmd ) );
676             }
677         }
678
679         default:
680             msg_Dbg( pIntf, "control query not supported" );
681             break;
682     }
683
684     return VLC_SUCCESS;
685 }
686
687
688 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
689                               vlc_value_t oldVal, vlc_value_t newVal,
690                               void *pParam )
691 {
692     VlcProc *pThis = (VlcProc*)pParam;
693
694     // Post a set equalizer bands command
695     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
696                                              pThis->m_varEqBands,
697                                              newVal.psz_string );
698     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
699     pQueue->push( CmdGenericPtr( pCmd ) );
700
701     return VLC_SUCCESS;
702 }
703
704
705 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
706                                vlc_value_t oldVal, vlc_value_t newVal,
707                                void *pParam )
708 {
709     VlcProc *pThis = (VlcProc*)pParam;
710     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
711
712     // Post a set preamp command
713     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
714                                               (newVal.f_float + 20.0) / 40.0 );
715     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
716     pQueue->push( CmdGenericPtr( pCmd ) );
717
718     return VLC_SUCCESS;
719 }
720