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