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