~ubuntu-branches/debian/wheezy/vlc/wheezy

« back to all changes in this revision

Viewing changes to modules/gui/skins2/src/vlcproc.cpp

Tags: upstream-0.7.2.final
ImportĀ upstreamĀ versionĀ 0.7.2.final

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * vlcproc.cpp
 
3
 *****************************************************************************
 
4
 * Copyright (C) 2003 VideoLAN
 
5
 * $Id: vlcproc.cpp 7713 2004-05-18 14:50:19Z gbazin $
 
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 
23
 *****************************************************************************/
 
24
 
 
25
#include <vlc/aout.h>
 
26
#include <vlc/vout.h>
 
27
 
 
28
#include "vlcproc.hpp"
 
29
#include "os_factory.hpp"
 
30
#include "os_timer.hpp"
 
31
#include "var_manager.hpp"
 
32
#include "../commands/async_queue.hpp"
 
33
#include "../commands/cmd_quit.hpp"
 
34
#include "../commands/cmd_vars.hpp"
 
35
#include "../utils/var_bool.hpp"
 
36
 
 
37
 
 
38
VlcProc *VlcProc::instance( intf_thread_t *pIntf )
 
39
{
 
40
    if( pIntf->p_sys->p_vlcProc == NULL )
 
41
    {
 
42
        pIntf->p_sys->p_vlcProc = new VlcProc( pIntf );
 
43
    }
 
44
 
 
45
    return pIntf->p_sys->p_vlcProc;
 
46
}
 
47
 
 
48
 
 
49
void VlcProc::destroy( intf_thread_t *pIntf )
 
50
{
 
51
    if( pIntf->p_sys->p_vlcProc )
 
52
    {
 
53
        delete pIntf->p_sys->p_vlcProc;
 
54
        pIntf->p_sys->p_vlcProc = NULL;
 
55
    }
 
56
}
 
57
 
 
58
 
 
59
VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
 
60
                  m_pVoutWindow( NULL ), m_pVout( NULL )
 
61
{
 
62
    // Create a timer to poll the status of the vlc
 
63
    OSFactory *pOsFactory = OSFactory::instance( pIntf );
 
64
    m_pTimer = pOsFactory->createOSTimer( Callback( this, &doManage ) );
 
65
    m_pTimer->start( 100, false );
 
66
 
 
67
    // Create and register VLC variables
 
68
    VarManager *pVarManager = VarManager::instance( getIntf() );
 
69
 
 
70
#define REGISTER_VAR( var, type, name ) \
 
71
    var = VariablePtr( new type( getIntf() ) ); \
 
72
    pVarManager->registerVar( var, name );
 
73
    REGISTER_VAR( m_cPlaylist, Playlist, "playlist" )
 
74
    pVarManager->registerVar( getPlaylistVar().getPositionVarPtr(),
 
75
                              "playlist.slider" );
 
76
    REGISTER_VAR( m_cVarRandom, VarBoolImpl, "playlist.isRandom" )
 
77
    REGISTER_VAR( m_cVarLoop, VarBoolImpl, "playlist.isLoop" )
 
78
    REGISTER_VAR( m_cVarTime, StreamTime, "time" )
 
79
    REGISTER_VAR( m_cVarVolume, Volume, "volume" )
 
80
    REGISTER_VAR( m_cVarStream, Stream, "stream" )
 
81
    REGISTER_VAR( m_cVarMute, VarBoolImpl, "vlc.isMute" ) // XXX broken
 
82
    REGISTER_VAR( m_cVarPlaying, VarBoolImpl, "vlc.isPlaying" )
 
83
    REGISTER_VAR( m_cVarStopped, VarBoolImpl, "vlc.isStopped" )
 
84
    REGISTER_VAR( m_cVarPaused, VarBoolImpl, "vlc.isPaused" )
 
85
    REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
 
86
#undef REGISTER_VAR
 
87
 
 
88
    // XXX WARNING XXX
 
89
    // The object variable callbacks are called from other VLC threads,
 
90
    // so they must put commands in the queue and NOT do anything else
 
91
    // (X11 calls are not reentrant)
 
92
 
 
93
    // Called when the playlist changes
 
94
    var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
 
95
                     onIntfChange, this );
 
96
    // Called when the current played item changes
 
97
    var_AddCallback( pIntf->p_sys->p_playlist, "playlist-current",
 
98
                     onPlaylistChange, this );
 
99
    // Called when a playlist item changed
 
100
    var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
 
101
                     onItemChange, this );
 
102
 
 
103
    // Callbacks for vout requests
 
104
    getIntf()->pf_request_window = &getWindow;
 
105
    getIntf()->pf_release_window = &releaseWindow;
 
106
    getIntf()->pf_control_window = &controlWindow;
 
107
 
 
108
    getIntf()->p_sys->p_input = NULL;
 
109
}
 
110
 
 
111
 
 
112
VlcProc::~VlcProc()
 
113
{
 
114
    m_pTimer->stop();
 
115
    delete( m_pTimer );
 
116
    if( getIntf()->p_sys->p_input )
 
117
    {
 
118
        vlc_object_release( getIntf()->p_sys->p_input );
 
119
    }
 
120
 
 
121
    // Callbacks for vout requests
 
122
    getIntf()->pf_request_window = NULL;
 
123
    getIntf()->pf_release_window = NULL;
 
124
    getIntf()->pf_control_window = NULL;
 
125
 
 
126
    var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
 
127
                     onIntfChange, this );
 
128
    var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-current",
 
129
                     onPlaylistChange, this );
 
130
    var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
 
131
                     onItemChange, this );
 
132
}
 
133
 
 
134
 
 
135
void VlcProc::setVoutWindow( void *pVoutWindow )
 
136
{
 
137
    m_pVoutWindow = pVoutWindow;
 
138
    // Reparent the vout window
 
139
    if( m_pVout )
 
140
    {
 
141
        if( vout_Control( m_pVout, VOUT_REPARENT ) != VLC_SUCCESS )
 
142
            vout_Control( m_pVout, VOUT_CLOSE );
 
143
    }
 
144
}
 
145
 
 
146
 
 
147
void VlcProc::manage()
 
148
{
 
149
    // Did the user requested to quit vlc ?
 
150
    if( getIntf()->b_die || getIntf()->p_vlc->b_die )
 
151
    {
 
152
        CmdQuit *pCmd = new CmdQuit( getIntf() );
 
153
        AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
 
154
        pQueue->push( CmdGenericPtr( pCmd ) );
 
155
    }
 
156
 
 
157
    // Get the VLC variables
 
158
    StreamTime *pTime = (StreamTime*)m_cVarTime.get();
 
159
    Volume *pVolume = (Volume*)m_cVarVolume.get();
 
160
    VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
 
161
    VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
 
162
    VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
 
163
    VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
 
164
    VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
 
165
    VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
 
166
    VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
 
167
 
 
168
    // Refresh sound volume
 
169
    audio_volume_t volume;
 
170
    aout_VolumeGet( getIntf(), &volume );
 
171
    pVolume->set( (double)volume / AOUT_VOLUME_MAX );
 
172
    // Set the mute variable
 
173
    pVarMute->set( volume == 0 );
 
174
 
 
175
    // Update the input
 
176
    if( getIntf()->p_sys->p_input == NULL )
 
177
    {
 
178
        getIntf()->p_sys->p_input = (input_thread_t *)vlc_object_find(
 
179
            getIntf(), VLC_OBJECT_INPUT, FIND_ANYWHERE );
 
180
    }
 
181
    else if( getIntf()->p_sys->p_input->b_dead )
 
182
    {
 
183
        vlc_object_release( getIntf()->p_sys->p_input );
 
184
        getIntf()->p_sys->p_input = NULL;
 
185
    }
 
186
 
 
187
    input_thread_t *pInput = getIntf()->p_sys->p_input;
 
188
 
 
189
    if( pInput && !pInput->b_die )
 
190
    {
 
191
        // Refresh time variables
 
192
        if( pInput->stream.b_seekable )
 
193
        {
 
194
            // Refresh position in the stream
 
195
            vlc_value_t pos;
 
196
            var_Get( pInput, "position", &pos );
 
197
            if( pos.f_float >= 0.0 )
 
198
            {
 
199
                pTime->set( pos.f_float, false );
 
200
            }
 
201
        }
 
202
        else
 
203
        {
 
204
            pTime->set( 0, false );
 
205
        }
 
206
 
 
207
        // Get the status of the playlist
 
208
        playlist_status_t status = getIntf()->p_sys->p_playlist->i_status;
 
209
 
 
210
        pVarPlaying->set( status == PLAYLIST_RUNNING );
 
211
        pVarStopped->set( status == PLAYLIST_STOPPED );
 
212
        pVarPaused->set( status == PLAYLIST_PAUSED );
 
213
        pVarSeekable->set( pInput->stream.b_seekable );
 
214
    }
 
215
    else
 
216
    {
 
217
        pVarPlaying->set( false );
 
218
        pVarPaused->set( false );
 
219
        pVarStopped->set( true );
 
220
        pVarSeekable->set( false );
 
221
        pTime->set( 0, false );
 
222
    }
 
223
 
 
224
    // Refresh the random variable
 
225
    vlc_value_t val;
 
226
    var_Get( getIntf()->p_sys->p_playlist, "random", &val );
 
227
    pVarRandom->set( val.b_bool );
 
228
 
 
229
    // Refresh the loop variable
 
230
    var_Get( getIntf()->p_sys->p_playlist, "loop", &val );
 
231
    pVarLoop->set( val.b_bool );
 
232
}
 
233
 
 
234
 
 
235
void VlcProc::doManage( SkinObject *pObj )
 
236
{
 
237
    VlcProc *pThis = (VlcProc*)pObj;
 
238
    pThis->manage();
 
239
}
 
240
 
 
241
 
 
242
int VlcProc::onIntfChange( vlc_object_t *pObj, const char *pVariable,
 
243
                           vlc_value_t oldVal, vlc_value_t newVal,
 
244
                           void *pParam )
 
245
{
 
246
    VlcProc *pThis = ( VlcProc* )pParam;
 
247
 
 
248
    // Create a playlist notify command
 
249
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
 
250
 
 
251
    // Push the command in the asynchronous command queue
 
252
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
 
253
    pQueue->remove( "notify playlist" );
 
254
    pQueue->push( CmdGenericPtr( pCmd ) );
 
255
 
 
256
    return VLC_SUCCESS;
 
257
}
 
258
 
 
259
 
 
260
int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
 
261
                           vlc_value_t oldVal, vlc_value_t newVal,
 
262
                           void *pParam )
 
263
{
 
264
    VlcProc *pThis = ( VlcProc* )pParam;
 
265
 
 
266
    // Create a playlist notify command
 
267
    // TODO: selective update
 
268
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
 
269
 
 
270
    // Push the command in the asynchronous command queue
 
271
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
 
272
    pQueue->remove( "notify playlist" );
 
273
    pQueue->push( CmdGenericPtr( pCmd ) );
 
274
 
 
275
    return VLC_SUCCESS;
 
276
}
 
277
 
 
278
 
 
279
int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
 
280
                               vlc_value_t oldVal, vlc_value_t newVal,
 
281
                               void *pParam )
 
282
{
 
283
    VlcProc *pThis = ( VlcProc* )pParam;
 
284
 
 
285
    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
 
286
 
 
287
    playlist_t *p_playlist = (playlist_t*)pObj;
 
288
    if( p_playlist->p_input )
 
289
    {
 
290
        // Create a command to update the stream variable
 
291
        // XXX: we should not need to access p_inpu->psz_source directly, a
 
292
        // getter should be provided by VLC core
 
293
        Stream *pStream = (Stream*)pThis->m_cVarStream.get();
 
294
        UString srcName( pThis->getIntf(),
 
295
                         p_playlist->p_input->psz_source );
 
296
        CmdSetStream *pCmd = new CmdSetStream( pThis->getIntf(), *pStream,
 
297
                                               srcName, false );
 
298
        // Push the command in the asynchronous command queue
 
299
        pQueue->remove( "set stream" );
 
300
        pQueue->push( CmdGenericPtr( pCmd ) );
 
301
    }
 
302
 
 
303
    // Create a playlist notify command
 
304
    // TODO: selective update
 
305
    CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
 
306
 
 
307
    // Push the command in the asynchronous command queue
 
308
    pQueue->remove( "notify playlist" );
 
309
    pQueue->push( CmdGenericPtr( pCmd ) );
 
310
 
 
311
    return VLC_SUCCESS;
 
312
}
 
313
 
 
314
 
 
315
void *VlcProc::getWindow( intf_thread_t *pIntf, vout_thread_t *pVout,
 
316
                          int *pXHint, int *pYHint,
 
317
                          unsigned int *pWidthHint,
 
318
                          unsigned int *pHeightHint )
 
319
{
 
320
    VlcProc *pThis = pIntf->p_sys->p_vlcProc;
 
321
    pThis->m_pVout = pVout;
 
322
    return pThis->m_pVoutWindow;
 
323
}
 
324
 
 
325
 
 
326
void VlcProc::releaseWindow( intf_thread_t *pIntf, void *pWindow )
 
327
{
 
328
    VlcProc *pThis = pIntf->p_sys->p_vlcProc;
 
329
    pThis->m_pVout = NULL;
 
330
}
 
331
 
 
332
 
 
333
int VlcProc::controlWindow( intf_thread_t *pIntf, void *pWindow,
 
334
                            int query, va_list args )
 
335
{
 
336
    return VLC_SUCCESS;
 
337
}
 
338