vlcproc.cpp 24.9 KB
Newer Older
1
2
3
/*****************************************************************************
 * vlcproc.cpp
 *****************************************************************************
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
11
12
13
14
15
16
17
18
19
20
21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
dionoea's avatar
dionoea committed
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
30
31

#include "vlcproc.hpp"
#include "os_factory.hpp"
#include "os_timer.hpp"
Cyril Deguet's avatar
Cyril Deguet committed
32
#include "var_manager.hpp"
33
34
#include "theme.hpp"
#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"
zorglub's avatar
zorglub committed
41
#include "../commands/cmd_dialogs.hpp"
42
#include "../utils/var_bool.hpp"
43
#include <sstream>
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66


VlcProc *VlcProc::instance( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_vlcProc == NULL )
    {
        pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
    }

    return pIntf->p_sys->p_vlcProc;
}


void VlcProc::destroy( intf_thread_t *pIntf )
{
    if( pIntf->p_sys->p_vlcProc )
    {
        delete pIntf->p_sys->p_vlcProc;
        pIntf->p_sys->p_vlcProc = NULL;
    }
}


67
VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
68
69
    m_varVoutSize( pIntf ), m_varEqBands( pIntf ),
    m_pVout( NULL ), m_pAout( NULL ), m_cmdManage( this )
70
71
72
{
    // Create a timer to poll the status of the vlc
    OSFactory *pOsFactory = OSFactory::instance( pIntf );
73
    m_pTimer = pOsFactory->createOSTimer( m_cmdManage );
74
75
    m_pTimer->start( 100, false );

Cyril Deguet's avatar
Cyril Deguet committed
76
77
    // Create and register VLC variables
    VarManager *pVarManager = VarManager::instance( getIntf() );
78

79
80
81
#define REGISTER_VAR( var, type, name ) \
    var = VariablePtr( new type( getIntf() ) ); \
    pVarManager->registerVar( var, name );
zorglub's avatar
zorglub committed
82
83

    /* Playlist variables */
Cyril Deguet's avatar
Cyril Deguet committed
84
85
86
    REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
    pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
                              "playlist.slider" );
87
    REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
88
    REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
89
    REGISTER_VAR( m_cVarRepeat, VarBoolImpl, "playlist.isRepeat" )
90
91
92
    REGISTER_VAR( m_cPlaytree, Playtree, "playtree" )
    pVarManager->registerVar( getPlaytreeVar().getPositionVarPtr(),
                              "playtree.slider" );
93
94
    pVarManager->registerVar( m_cVarRandom, "playtree.isRandom" );
    pVarManager->registerVar( m_cVarLoop, "playtree.isLoop" );
zorglub's avatar
zorglub committed
95

96
97
98
    REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
    REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
    REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
zorglub's avatar
zorglub committed
99
100
101
102

    /* Input variables */
    pVarManager->registerVar( m_cVarRepeat, "playtree.isRepeat" );
    REGISTER_VAR( m_cVarTime, StreamTime, "time" )
103
    REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
104
    REGISTER_VAR( m_cVarDvdActive, VarBoolImpl, "dvd.isActive" )
zorglub's avatar
zorglub committed
105
106

    /* Vout variables */
107
    REGISTER_VAR( m_cVarFullscreen, VarBoolImpl, "vlc.isFullscreen" )
108
    REGISTER_VAR( m_cVarHasVout, VarBoolImpl, "vlc.hasVout" )
zorglub's avatar
zorglub committed
109
110

    /* Aout variables */
zorglub's avatar
zorglub committed
111
    REGISTER_VAR( m_cVarHasAudio, VarBoolImpl, "vlc.hasAudio" )
zorglub's avatar
zorglub committed
112
113
114
115
116
    REGISTER_VAR( m_cVarVolume, Volume, "volume" )
    REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" )
    REGISTER_VAR( m_cVarEqualizer, VarBoolImpl, "equalizer.isEnabled" )
    REGISTER_VAR( m_cVarEqPreamp, EqualizerPreamp, "equalizer.preamp" )

117
#undef REGISTER_VAR
118
119
120
121
    m_cVarStreamName = VariablePtr( new VarText( getIntf(), false ) );
    pVarManager->registerVar( m_cVarStreamName, "streamName" );
    m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) );
    pVarManager->registerVar( m_cVarStreamURI, "streamURI" );
122
123
    m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) );
    pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" );
124
125
    m_cVarStreamSampleRate = VariablePtr( new VarText( getIntf(), false ) );
    pVarManager->registerVar( m_cVarStreamSampleRate, "samplerate" );
Cyril Deguet's avatar
Cyril Deguet committed
126

127
128
129
130
131
132
133
134
    // Register the equalizer bands
    for( int i = 0; i < EqualizerBands::kNbBands; i++)
    {
        stringstream ss;
        ss << "equalizer.band(" << i << ")";
        pVarManager->registerVar( m_varEqBands.getBand( i ), ss.str() );
    }

135
136
137
138
139
    // XXX WARNING XXX
    // The object variable callbacks are called from other VLC threads,
    // so they must put commands in the queue and NOT do anything else
    // (X11 calls are not reentrant)

140
    // Called when the playlist changes
141
    var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
142
                     onIntfChange, this );
143
    // Called when a playlist item is added
zorglub's avatar
zorglub committed
144
    var_AddCallback( pIntf->p_sys->p_playlist, "item-append",
zorglub's avatar
zorglub committed
145
                     onItemAppend, this );
146
147
148
    // Called when a playlist item is deleted
    // TODO: properly handle item-deleted
    var_AddCallback( pIntf->p_sys->p_playlist, "item-deleted",
zorglub's avatar
zorglub committed
149
                     onItemDelete, this );
150
151
152
    // Called when the "interface shower" wants us to show the skin
    var_AddCallback( pIntf->p_sys->p_playlist, "intf-show",
                     onIntfShow, this );
153
    // Called when the current played item changes
154
    var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
155
                     onPlaylistChange, this );
156
157
    // Called when a playlist item changed
    var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
158
                     onItemChange, this );
159
160
    // Called when our skins2 demux wants us to load a new skin
    var_AddCallback( pIntf, "skin-to-load", onSkinToLoad, this );
161

zorglub's avatar
zorglub committed
162
163
164
165
166
    // Called when we have an interaction dialog to display
    var_Create( pIntf, "interaction", VLC_VAR_ADDRESS );
    var_AddCallback( pIntf, "interaction", onInteraction, this );
    pIntf->b_interaction = VLC_TRUE;

167
168
169
170
171
    // Callbacks for vout requests
    getIntf()->pf_request_window = &getWindow;
    getIntf()->pf_release_window = &releaseWindow;
    getIntf()->pf_control_window = &controlWindow;

172
173
174
175
176
177
178
179
180
181
182
183
    getIntf()->p_sys->p_input = NULL;
}


VlcProc::~VlcProc()
{
    m_pTimer->stop();
    delete( m_pTimer );
    if( getIntf()->p_sys->p_input )
    {
        vlc_object_release( getIntf()->p_sys->p_input );
    }
184
185
186
187
188
189
190
191

    // Callbacks for vout requests
    getIntf()->pf_request_window = NULL;
    getIntf()->pf_release_window = NULL;
    getIntf()->pf_control_window = NULL;

    var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
                     onIntfChange, this );
192
    var_DelCallback( getIntf()->p_sys->p_playlist, "item-append",
zorglub's avatar
zorglub committed
193
                     onItemAppend, this );
194
    var_DelCallback( getIntf()->p_sys->p_playlist, "item-deleted",
zorglub's avatar
zorglub committed
195
                     onItemDelete, this );
196
197
    var_DelCallback( getIntf()->p_sys->p_playlist, "intf-show",
                     onIntfShow, this );
198
199
200
201
    var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
                     onPlaylistChange, this );
    var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
                     onItemChange, this );
202
    var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
203
204
205
}


206
void VlcProc::registerVoutWindow( void *pVoutWindow )
207
{
208
    m_handleSet.insert( pVoutWindow );
209
210
211
212
213
214
215
216
217
    // Reparent the vout window
    if( m_pVout )
    {
        if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
            vout_Control( m_pVout, VOUT_CLOSE );
    }
}


218
219
220
221
222
223
void VlcProc::unregisterVoutWindow( void *pVoutWindow )
{
    m_handleSet.erase( pVoutWindow );
}


224
225
226
227
228
229
void VlcProc::dropVout()
{
    if( m_pVout )
    {
        if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
            vout_Control( m_pVout, VOUT_CLOSE );
Cyril Deguet's avatar
Cyril Deguet committed
230
        m_pVout = NULL;
231
232
233
234
    }
}


235
236
void VlcProc::manage()
{
zorglub's avatar
zorglub committed
237
    // Did the user request to quit vlc ?
238
    if( getIntf()->b_die || getIntf()->p_vlc->b_die )
239
240
241
242
243
244
    {
        CmdQuit *pCmd = new CmdQuit( getIntf() );
        AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
        pQueue->push( CmdGenericPtr( pCmd ) );
    }

zorglub's avatar
zorglub committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    refreshPlaylist();
    refreshAudio();
    refreshInput();
}
void VlcProc::CmdManage::execute()
{
    // Just forward to VlcProc
    m_pParent->manage();
}

void VlcProc::refreshAudio()
{
    char *pFilters = NULL;

    // Check if the audio output has changed
    aout_instance_t *pAout = (aout_instance_t *)vlc_object_find( getIntf(),
            VLC_OBJECT_AOUT, FIND_ANYWHERE );
    if( pAout )
    {
        if( pAout != m_pAout )
        {
            // Register the equalizer callbacks
            if( !var_AddCallback( pAout, "equalizer-bands",
                                  onEqBandsChange, this ) &&
                !var_AddCallback( pAout, "equalizer-preamp",
                                  onEqPreampChange, this ) )
            {
                m_pAout = pAout;
                //char * psz_bands = var_GetString( p_aout, "equalizer-bands" );
            }
        }
        // Get the audio filters
        pFilters = var_GetString( pAout, "audio-filter" );
        vlc_object_release( pAout );
    }
    else
    {
        // Get the audio filters
        pFilters = config_GetPsz( getIntf(), "audio-filter" );
    }

    // Refresh sound volume
    audio_volume_t volume;
    aout_VolumeGet( getIntf(), &volume );
    Volume *pVolume = (Volume*)m_cVarVolume.get();
    pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX );

    // Set the mute variable
    VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
    pVarMute->set( volume == 0 );

    // Refresh the equalizer variable
    VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
    pVarEqualizer->set( pFilters && strstr( pFilters, "equalizer" ) );
}

void VlcProc::refreshPlaylist()
{
    // Refresh the random variable
304
    VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
zorglub's avatar
zorglub committed
305
306
307
308
309
    vlc_value_t val;
    var_Get( getIntf()->p_sys->p_playlist, "random", &val );
    pVarRandom->set( val.b_bool != 0 );

    // Refresh the loop variable
310
    VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
zorglub's avatar
zorglub committed
311
312
313
314
    var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
    pVarLoop->set( val.b_bool != 0 );

    // Refresh the repeat variable
315
    VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
zorglub's avatar
zorglub committed
316
317
318
319
320
321
322
323
    var_Get( getIntf()->p_sys->p_playlist, "repeat", &val );
    pVarRepeat->set( val.b_bool != 0 );
}

void VlcProc::refreshInput()
{
    StreamTime *pTime = (StreamTime*)m_cVarTime.get();
    VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
324
    VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
325
    VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
zorglub's avatar
zorglub committed
326
    VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get();
327
    VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get();
328
    VarText *pSampleRate = (VarText*)m_cVarStreamSampleRate.get();
zorglub's avatar
zorglub committed
329
    VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
330
331
332
333
334
    VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
    VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
    VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();

    input_thread_t *pInput = getIntf()->p_sys->p_input;
335

336
    // Update the input
337
338
    if( getIntf()->p_sys->p_input == NULL )
    {
zorglub's avatar
zorglub committed
339
340
341
        getIntf()->p_sys->p_input = getIntf()->p_sys->p_playlist->p_input;
        if( getIntf()->p_sys->p_input )
            vlc_object_yield( getIntf()->p_sys->p_input );
342
343
344
345
346
347
348
349
350
351
352
    }
    else if( getIntf()->p_sys->p_input->b_dead )
    {
        vlc_object_release( getIntf()->p_sys->p_input );
        getIntf()->p_sys->p_input = NULL;
    }


    if( pInput && !pInput->b_die )
    {
        // Refresh time variables
353
354
355
356
        vlc_value_t pos;
        var_Get( pInput, "position", &pos );
        pTime->set( pos.f_float, false );
        pVarSeekable->set( pos.f_float != 0.0 );
357
358
359
360

        // Refresh DVD detection
        vlc_value_t chapters_count;
        var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
zorglub's avatar
zorglub committed
361
                        &chapters_count, NULL );
362
        pVarDvdActive->set( chapters_count.i_int > 0 );
363

zorglub's avatar
zorglub committed
364
365
366
367
368
369
370
371
372
373
374
375
376
377
        // Get the input bitrate
        int bitrate = var_GetInteger( pInput, "bit-rate" ) / 1000;
        pBitrate->set( UString::fromInt( getIntf(), bitrate ) );

        // Get the audio sample rate
        int sampleRate = var_GetInteger( pInput, "sample-rate" ) / 1000;
        pSampleRate->set( UString::fromInt( getIntf(), sampleRate ) );

        // Do we have audio
        vlc_value_t audio_es;
        var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
                        &audio_es, NULL );
        pVarHasAudio->set( audio_es.i_int > 0 );

378
379
        // Refresh fullscreen status
        vout_thread_t *pVout = (vout_thread_t *)vlc_object_find( pInput,
zorglub's avatar
zorglub committed
380
                                     VLC_OBJECT_VOUT, FIND_CHILD );
381
        pVarHasVout->set( pVout != NULL );
382
383
384
385
386
        if( pVout )
        {
            pVarFullscreen->set( pVout->b_fullscreen );
            vlc_object_release( pVout );
        }
387
388
389
390
391
392

        // Refresh play/pause status
        int state = var_GetInteger( pInput, "state" );
        pVarStopped->set( false );
        pVarPlaying->set( state != PAUSE_S );
        pVarPaused->set( state == PAUSE_S );
393
394
395
    }
    else
    {
396
        pVarSeekable->set( false );
397
        pVarDvdActive->set( false );
Cyril Deguet's avatar
Cyril Deguet committed
398
        pTime->set( 0, false );
399
        pVarFullscreen->set( false );
zorglub's avatar
zorglub committed
400
        pVarHasAudio->set( false );
401
        pVarHasVout->set( false );
402
403
404
        pVarStopped->set( true );
        pVarPlaying->set( false );
        pVarPaused->set( false );
405
406
407
    }
}

408
409
410
411
int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
                           vlc_value_t oldVal, vlc_value_t newVal,
                           void *pParam )
{
412
    VlcProc *pThis = (VlcProc*)pParam;
413

414
415
416
417
    // Update the stream variable
    playlist_t *p_playlist = (playlist_t*)pObj;
    pThis->updateStreamName(p_playlist);

zorglub's avatar
zorglub committed
418
    // Create a playlist notify command (for old style playlist)
419
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
zorglub's avatar
zorglub committed
420
    // Create a playtree notify command (for new style playtree)
421
    CmdPlaytreeChanged *pCmdTree = new CmdPlaytreeChanged( pThis->getIntf() );
422
423
424
425

    // Push the command in the asynchronous command queue
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );
426
    pQueue->push( CmdGenericPtr( pCmdTree ) );
427
428
429
430
431

    return VLC_SUCCESS;
}


432
433
434
435
436
437
438
439
440
int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
                         vlc_value_t oldVal, vlc_value_t newVal,
                         void *pParam )
{
    if (newVal.i_int)
    {
        VlcProc *pThis = (VlcProc*)pParam;

        // Create a raise all command
441
442
        CmdRaiseAll *pCmd = new CmdRaiseAll( pThis->getIntf(),
            pThis->getIntf()->p_sys->p_theme->getWindowManager() );
443
444
445
446
447
448
449
450
451
452

        // Push the command in the asynchronous command queue
        AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
        pQueue->push( CmdGenericPtr( pCmd ) );
    }

    return VLC_SUCCESS;
}


453
454
455
456
int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
                           vlc_value_t oldVal, vlc_value_t newVal,
                           void *pParam )
{
457
    VlcProc *pThis = (VlcProc*)pParam;
458

459
460
461
462
    // Update the stream variable
    playlist_t *p_playlist = (playlist_t*)pObj;
    pThis->updateStreamName(p_playlist);

463
464
465
    // Create a playlist notify command
    // TODO: selective update
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
466
    // Create a playtree notify command
467
468
    CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
                                                         newVal.i_int );
469
470
471
472

    // Push the command in the asynchronous command queue
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );
473
    pQueue->push( CmdGenericPtr( pCmdTree ), true );
474

475
476
477
    return VLC_SUCCESS;
}

zorglub's avatar
zorglub committed
478
479
480
481
482
483
484
485
486
487
488
int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable,
                           vlc_value_t oldVal, vlc_value_t newVal,
                           void *pParam )
{
    VlcProc *pThis = (VlcProc*)pParam;

    playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(
                                                playlist_add_t ) ) ;

    memcpy( p_add, newVal.p_address, sizeof( playlist_add_t ) ) ;

zorglub's avatar
zorglub committed
489
490
491
492
493
    CmdGenericPtr ptrTree;
    CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(),
                                                             p_add );
    ptrTree = CmdGenericPtr( pCmdTree );

zorglub's avatar
zorglub committed
494
495
496
497
498
499
    // Create a playlist notify command (for old style playlist)
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );

    // Push the command in the asynchronous command queue
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );
zorglub's avatar
zorglub committed
500
    pQueue->push( ptrTree , false );
zorglub's avatar
zorglub committed
501
502
503
504

    return VLC_SUCCESS;
}

zorglub's avatar
zorglub committed
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
                           vlc_value_t oldVal, vlc_value_t newVal,
                           void *pParam )
{
    VlcProc *pThis = (VlcProc*)pParam;

    int i_id = newVal.i_int;

    CmdGenericPtr ptrTree;
    CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(),
                                                         i_id);
    ptrTree = CmdGenericPtr( pCmdTree );

    // Create a playlist notify command (for old style playlist)
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );

    // Push the command in the asynchronous command queue
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );
    pQueue->push( ptrTree , false );

    return VLC_SUCCESS;
}


zorglub's avatar
zorglub committed
530

531

532
533
534
535
int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
                               vlc_value_t oldVal, vlc_value_t newVal,
                               void *pParam )
{
536
    VlcProc *pThis = (VlcProc*)pParam;
537

538
539
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );

540
    // Update the stream variable
541
    playlist_t *p_playlist = (playlist_t*)pObj;
542
    pThis->updateStreamName(p_playlist);
543

zorglub's avatar
zorglub committed
544
    // Create a playlist notify command (old style playlist)
545
    // TODO: selective update
546
547
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );
zorglub's avatar
zorglub committed
548
549
550
551
552
553
    // Create two playtree notify commands: one for old item, one for new
    CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
                                                         oldVal.i_int );
    pQueue->push( CmdGenericPtr( pCmdTree ) , true );
    pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), newVal.i_int );
    pQueue->push( CmdGenericPtr( pCmdTree ) , true );
554

555
556
557
    return VLC_SUCCESS;
}

558

559
560
561
562
int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
                           vlc_value_t oldVal, vlc_value_t newVal,
                           void *pParam )
{
563
    VlcProc *pThis = (VlcProc*)pParam;
564
565
566
567
568
569
570
571
572
573
574
575

    // Create a playlist notify command
    CmdChangeSkin *pCmd =
        new CmdChangeSkin( pThis->getIntf(), newVal.psz_string );

    // Push the command in the asynchronous command queue
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );

    return VLC_SUCCESS;
}

zorglub's avatar
zorglub committed
576
577
578
579
580
581
582
583
584
585
586
587
588
int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable,
                            vlc_value_t oldVal, vlc_value_t newVal,
                            void *pParam )
{
    VlcProc *pThis = (VlcProc*)pParam;
    interaction_dialog_t *p_dialog = (interaction_dialog_t *)(newVal.p_address);

    CmdInteraction *pCmd = new CmdInteraction( pThis->getIntf(), p_dialog );
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );
    return VLC_SUCCESS;
}

589

590
591
void VlcProc::updateStreamName( playlist_t *p_playlist )
{
592
    if( p_playlist && p_playlist->p_input )
593
    {
594
595
596
        // Get playlist item information
        input_item_t *pItem = p_playlist->p_input->input.p_item;

597
598
599
600
        VarText &rStreamName = getStreamNameVar();
        VarText &rStreamURI = getStreamURIVar();
        // XXX: we should not need to access p_input->psz_source directly, a
        // getter should be provided by VLC core
601
        string name = pItem->psz_name;
602
603
604
605
606
607
608
609
610
        // XXX: This should be done in VLC core, not here...
        // Remove path information if any
        OSFactory *pFactory = OSFactory::instance( getIntf() );
        string::size_type pos = name.rfind( pFactory->getDirSeparator() );
        if( pos != string::npos )
        {
            name = name.substr( pos + 1, name.size() - pos + 1 );
        }
        UString srcName( getIntf(), name.c_str() );
611
        UString srcURI( getIntf(), pItem->psz_uri );
612

613
       // Create commands to update the stream variables
614
615
616
617
        CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName );
        CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
        // Push the commands in the asynchronous command queue
        AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
618
619
        pQueue->push( CmdGenericPtr( pCmd1 ), false );
        pQueue->push( CmdGenericPtr( pCmd2 ), false );
620
621
622
623
    }
}


624
625
626
627
628
629
void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
                          int *pXHint, int *pYHint,
                          unsigned int *pWidthHint,
                          unsigned int *pHeightHint )
{
    VlcProc *pThis = pIntf->p_sys->p_vlcProc;
630
631
632
633
634
635
    if( pThis->m_handleSet.empty() )
    {
        return NULL;
    }
    else
    {
Cyril Deguet's avatar
Cyril Deguet committed
636
        pThis->m_pVout = pVout;
637
638
639
640
641
642
643
644
        // Get the window handle
        void *pWindow = *pThis->m_handleSet.begin();
        // Post a resize vout command
        CmdResizeVout *pCmd = new CmdResizeVout( pThis->getIntf(), pWindow,
                                                 *pWidthHint, *pHeightHint );
        AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
        pQueue->push( CmdGenericPtr( pCmd ) );
        return pWindow;
645
    }
646
647
648
649
650
651
652
653
654
655
656
657
658
}


void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
{
    VlcProc *pThis = pIntf->p_sys->p_vlcProc;
    pThis->m_pVout = NULL;
}


int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
                            int query, va_list args )
{
659
660
661
662
    VlcProc *pThis = pIntf->p_sys->p_vlcProc;

    switch( query )
    {
663
        case VOUT_SET_SIZE:
664
665
666
        {
            if( pThis->m_pVout )
            {
667
668
669
670
671
                unsigned int i_width  = va_arg( args, unsigned int );
                unsigned int i_height = va_arg( args, unsigned int );
                if( !i_width ) i_width = pThis->m_pVout->i_window_width;
                if( !i_height ) i_height = pThis->m_pVout->i_window_height;

672
673
674
                // Post a resize vout command
                CmdResizeVout *pCmd =
                    new CmdResizeVout( pThis->getIntf(), pWindow,
675
                                       i_width, i_height );
676
677
678
679
680
681
682
683
684
685
                AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
                pQueue->push( CmdGenericPtr( pCmd ) );
            }
        }

        default:
            msg_Dbg( pIntf, "control query not supported" );
            break;
    }

686
687
688
    return VLC_SUCCESS;
}

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable,
                              vlc_value_t oldVal, vlc_value_t newVal,
                              void *pParam )
{
    VlcProc *pThis = (VlcProc*)pParam;

    // Post a set equalizer bands command
    CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(),
                                             pThis->m_varEqBands,
                                             newVal.psz_string );
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );

    return VLC_SUCCESS;
}

706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722

int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable,
                               vlc_value_t oldVal, vlc_value_t newVal,
                               void *pParam )
{
    VlcProc *pThis = (VlcProc*)pParam;
    EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get());

    // Post a set preamp command
    CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp,
                                              (newVal.f_float + 20.0) / 40.0 );
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
    pQueue->push( CmdGenericPtr( pCmd ) );

    return VLC_SUCCESS;
}