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