]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vlcproc.cpp
3b0120507f6a6904d5cf18009440a971179b0714
[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 = getIntf()->p_sys->p_playlist->p_input;
332         if( getIntf()->p_sys->p_input )
333             vlc_object_yield( getIntf()->p_sys->p_input );
334     }
335     else if( getIntf()->p_sys->p_input->b_dead )
336     {
337         vlc_object_release( getIntf()->p_sys->p_input );
338         getIntf()->p_sys->p_input = NULL;
339     }
340
341
342     if( pInput && vlc_object_alive (pInput) )
343     {
344         // Refresh time variables
345         vlc_value_t pos;
346         var_Get( pInput, "position", &pos );
347         pTime->set( pos.f_float, false );
348         pVarSeekable->set( pos.f_float != 0.0 );
349
350         // Refresh DVD detection
351         vlc_value_t chapters_count;
352         var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
353                         &chapters_count, NULL );
354         pVarDvdActive->set( chapters_count.i_int > 0 );
355
356         // Get the input bitrate
357         int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
358         pBitrate->set( UString::fromInt( getIntf(), bitrate ) );
359
360         // Get the audio sample rate
361         int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
362         pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );
363
364         // Do we have audio
365         vlc_value_t audio_es;
366         var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
367                         &audio_es, NULL );
368         pVarHasAudio->set( audio_es.i_int > 0 );
369
370         // Refresh fullscreen status
371         vout_thread_t *pVout = (vout_thread_t *)vlc_object_find( pInput,
372                                      VLC_OBJECT_VOUT, FIND_CHILD );
373         pVarHasVout->set( pVout != NULL );
374         if( pVout )
375         {
376             pVarFullscreen->set( pVout->b_fullscreen );
377             vlc_object_release( pVout );
378         }
379
380         // Refresh play/pause status
381         int state = var_GetInteger( pInput, "state" );
382         pVarStopped->set( false );
383         pVarPlaying->set( state != PAUSE_S );
384         pVarPaused->set( state == PAUSE_S );
385     }
386     else
387     {
388         pVarSeekable->set( false );
389         pVarDvdActive->set( false );
390         pTime->set( 0, false );
391         pVarFullscreen->set( false );
392         pVarHasAudio->set( false );
393         pVarHasVout->set( false );
394         pVarStopped->set( true );
395         pVarPlaying->set( false );
396         pVarPaused->set( false );
397     }
398 }
399
400 int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
401                            vlc_value_t oldVal, vlc_value_t newVal,
402                            void *pParam )
403 {
404     VlcProc *pThis = (VlcProc*)pParam;
405
406     // Update the stream variable
407     playlist_t *p_playlist = (playlist_t*)pObj;
408     pThis->updateStreamName(p_playlist);
409
410     // Create a playtree notify command (for new style playtree)
411     CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
412
413     // Push the command in the asynchronous command queue
414     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
415     pQueue->push( CmdGenericPtr( pCmdTree ) );
416
417     return VLC_SUCCESS;
418 }
419
420
421 int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
422                          vlc_value_t oldVal, vlc_value_t newVal,
423                          void *pParam )
424 {
425     if (newVal.i_int)
426     {
427         VlcProc *pThis = (VlcProc*)pParam;
428
429         // Create a raise all command
430         CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
431             pThis->getIntf()->p_sys->p_theme->getWindowManager() );
432
433         // Push the command in the asynchronous command queue
434         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
435         pQueue->push( CmdGenericPtr( pCmd ) );
436     }
437
438     return VLC_SUCCESS;
439 }
440
441
442 int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
443                            vlc_value_t oldVal, vlc_value_t newVal,
444                            void *pParam )
445 {
446     VlcProc *pThis = (VlcProc*)pParam;
447
448     // Update the stream variable
449     playlist_t *p_playlist = (playlist_t*)pObj;
450     pThis->updateStreamName(p_playlist);
451
452     // Create a playtree notify command
453     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
454                                                          newVal.i_int );
455
456     // Push the command in the asynchronous command queue
457     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
458     pQueue->push( CmdGenericPtr( pCmdTree ), true );
459
460     return VLC_SUCCESS;
461 }
462
463 int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
464                            vlc_value_t oldVal, vlc_value_t newVal,
465                            void *pParam )
466 {
467     VlcProc *pThis = (VlcProc*)pParam;
468
469     playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(
470                                                 playlist_add_t ) ) ;
471
472     memcpy( p_add, newVal.p_address, sizeof( playlist_add_t ) ) ;
473
474     CmdGenericPtr ptrTree;
475     CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
476                                                              p_add );
477     ptrTree = CmdGenericPtr( pCmdTree );
478
479     // Push the command in the asynchronous command queue
480     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
481     pQueue->push( ptrTree , false );
482
483     return VLC_SUCCESS;
484 }
485
486 int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
487                            vlc_value_t oldVal, vlc_value_t newVal,
488                            void *pParam )
489 {
490     VlcProc *pThis = (VlcProc*)pParam;
491
492     int i_id = newVal.i_int;
493
494     CmdGenericPtr ptrTree;
495     CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
496                                                          i_id);
497     ptrTree = CmdGenericPtr( pCmdTree );
498
499     // Push the command in the asynchronous command queue
500     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
501     pQueue->push( ptrTree , false );
502
503     return VLC_SUCCESS;
504 }
505
506
507 int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
508                                vlc_value_t oldVal, vlc_value_t newVal,
509                                void *pParam )
510 {
511     VlcProc *pThis = (VlcProc*)pParam;
512
513     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
514
515     // Update the stream variable
516     playlist_t *p_playlist = (playlist_t*)pObj;
517     pThis->updateStreamName(p_playlist);
518
519     // Create two playtree notify commands: one for old item, one for new
520     CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
521                                                          oldVal.i_int );
522     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
523     pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), newVal.i_int );
524     pQueue->push( CmdGenericPtr( pCmdTree ) , true );
525
526     return VLC_SUCCESS;
527 }
528
529
530 int VlcProc::onSkinToLoad( 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     // Create a playlist notify command
537     CmdChangeSkin *pCmd =
538         new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );
539
540     // Push the command in the asynchronous command queue
541     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
542     pQueue->push( CmdGenericPtr( pCmd ) );
543
544     return VLC_SUCCESS;
545 }
546
547 int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
548                             vlc_value_t oldVal, vlc_value_t newVal,
549                             void *pParam )
550 {
551     VlcProc *pThis = (VlcProc*)pParam;
552     interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);
553
554     CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
555     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
556     pQueue->push( CmdGenericPtr( pCmd ) );
557     return VLC_SUCCESS;
558 }
559
560
561 void VlcProc::updateStreamName( playlist_t *p_playlist )
562 {
563     if( p_playlist && p_playlist->p_input )
564     {
565         // Get playlist item information
566         input_item_t *pItem = input_GetItem(p_playlist->p_input);
567
568         VarText &rStreamName = getStreamNameVar();
569         VarText &rStreamURI = getStreamURIVar();
570         // XXX: we should not need to access p_input->psz_source directly, a
571         // getter should be provided by VLC core
572         string name = pItem->psz_name;
573         // XXX: This should be done in VLC core, not here...
574         // Remove path information if any
575         OSFactory *pFactory = OSFactory::instance( getIntf() );
576         string::size_type pos = name.rfind( pFactory->getDirSeparator() );
577         if( pos != string::npos )
578         {
579             name = name.substr( pos + 1, name.size() - pos + 1 );
580         }
581         UString srcName( getIntf(), name.c_str() );
582         UString srcURI( getIntf(), pItem->psz_uri );
583
584        // Create commands to update the stream variables
585         CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
586         CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
587         // Push the commands in the asynchronous command queue
588         AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
589         pQueue->push( CmdGenericPtr( pCmd1 ), false );
590         pQueue->push( CmdGenericPtr( pCmd2 ), false );
591     }
592 }
593
594
595 void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
596                           int *pXHint, int *pYHint,
597                           unsigned int *pWidthHint,
598                           unsigned int *pHeightHint )
599 {
600     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
601     if( pThis->m_handleSet.empty() )
602     {
603         return NULL;
604     }
605     else
606     {
607         pThis->m_pVout = pVout;
608         // Get the window handle
609         void *pWindow = *pThis->m_handleSet.begin();
610         // Post a resize vout command
611         CmdResizeVout *pCmd = new CmdResizeVout( pThis->getIntf(), pWindow,
612                                                  *pWidthHint, *pHeightHint );
613         AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
614         pQueue->push( CmdGenericPtr( pCmd ) );
615         return pWindow;
616     }
617 }
618
619
620 void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
621 {
622     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
623     pThis->m_pVout = NULL;
624 }
625
626
627 int VlcProc::controlWindow( struct vout_window_t *pWnd,
628                             int query, va_list args )
629 {
630     intf_thread_t *pIntf = (intf_thread_t *)pWnd->p_private;
631     VlcProc *pThis = pIntf->p_sys->p_vlcProc;
632
633     switch( query )
634     {
635         case VOUT_SET_SIZE:
636         {
637             if( pThis->m_pVout )
638             {
639                 unsigned int i_width  = va_arg( args, unsigned int );
640                 unsigned int i_height = va_arg( args, unsigned int );
641                 if( !i_width ) i_width = pThis->m_pVout->i_window_width;
642                 if( !i_height ) i_height = pThis->m_pVout->i_window_height;
643
644                 // Post a resize vout command
645                 CmdResizeVout *pCmd =
646                     new CmdResizeVout( pThis->getIntf(), pWnd->handle,
647                                        i_width, i_height );
648                 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
649                 pQueue->push( CmdGenericPtr( pCmd ) );
650             }
651         }
652
653         default:
654             msg_Dbg( pWnd, "control query not supported" );
655             break;
656     }
657
658     return VLC_SUCCESS;
659 }
660
661
662 int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
663                               vlc_value_t oldVal, vlc_value_t newVal,
664                               void *pParam )
665 {
666     VlcProc *pThis = (VlcProc*)pParam;
667
668     // Post a set equalizer bands command
669     CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
670                                              pThis->m_varEqBands,
671                                              newVal.psz_string );
672     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
673     pQueue->push( CmdGenericPtr( pCmd ) );
674
675     return VLC_SUCCESS;
676 }
677
678
679 int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
680                                vlc_value_t oldVal, vlc_value_t newVal,
681                                void *pParam )
682 {
683     VlcProc *pThis = (VlcProc*)pParam;
684     EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());
685
686     // Post a set preamp command
687     CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
688                                               (newVal.f_float + 20.0) / 40.0 );
689     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
690     pQueue->push( CmdGenericPtr( pCmd ) );
691
692     return VLC_SUCCESS;
693 }
694