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