libvlc.c 22.8 KB
Newer Older
1
2
3
/*****************************************************************************
 * libvlc.c: main libvlc source
 *****************************************************************************
4
 * Copyright (C) 1998-2006 the VideoLAN team
zorglub's avatar
zorglub committed
5
 * $Id$
6
7
8
 *
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
9
 *          Gildas Bazin <gbazin@videolan.org>
hartman's avatar
hartman committed
10
 *          Derk-Jan Hartman <hartman at videolan dot org>
11
 *          Rémi Denis-Courmont <rem # videolan : org>
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26
27
28
29
30
31
 *****************************************************************************/

/*****************************************************************************
 * Pretend we are a builtin module
 *****************************************************************************/
#define MODULE_NAME main
32
#define MODULE_PATH main
33
34
35
36
37
#define __BUILTIN__

/*****************************************************************************
 * Preamble
 *****************************************************************************/
38
#include <vlc/vlc.h>
Laurent Aimar's avatar
Laurent Aimar committed
39
#include <vlc/input.h>
40

zorglub's avatar
zorglub committed
41
#include <libvlc_internal.h>
42

zorglub's avatar
zorglub committed
43
#include <vlc_error.h>
44
45

#include "audio_output.h"
46
#include "vlc_video.h"
47
48
49
#include "video_output.h"

/*****************************************************************************
Sam Hocevar's avatar
Sam Hocevar committed
50
 * VLC_Version: return the libvlc version.
51
 *****************************************************************************
Sam Hocevar's avatar
Sam Hocevar committed
52
 * This function returns full version string (numeric version and codename).
53
 *****************************************************************************/
54
char const * VLC_Version( void )
55
{
Sam Hocevar's avatar
Sam Hocevar committed
56
    return VERSION_MESSAGE;
57
58
}

59
/*****************************************************************************
60
 * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain,
61
62
63
64
65
 * VLC_Compiler, VLC_Changeset
 *****************************************************************************/
#define DECLARE_VLC_VERSION( func, var )                                    \
char const * VLC_##func ( void )                                            \
{                                                                           \
66
    return VLC_##var ;                                                      \
67
68
}

69
70
DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
Christophe Mutricy's avatar
Typo    
Christophe Mutricy committed
71
DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
72
73
DECLARE_VLC_VERSION( Compiler, COMPILER );

74
#ifndef HAVE_SHARED_LIBVLC
75
76
77
78
79
extern const char psz_vlc_changeset[];
char const * VLC_Changeset( void )
{
    return psz_vlc_changeset;
}
80
#endif
81

82
83
84
85
86
87
88
89
90
91
/*****************************************************************************
 * VLC_Error: strerror() equivalent
 *****************************************************************************
 * This function returns full version string (numeric version and codename).
 *****************************************************************************/
char const * VLC_Error( int i_err )
{
    return vlc_error( i_err );
}

Sam Hocevar's avatar
Sam Hocevar committed
92
/*****************************************************************************
zorglub's avatar
zorglub committed
93
 * VLC_Create: allocate a libvlc instance and intialize global libvlc stuff if needed
Sam Hocevar's avatar
Sam Hocevar committed
94
 *****************************************************************************
zorglub's avatar
zorglub committed
95
 * This function allocates a libvlc instance and returns a negative value
Sam Hocevar's avatar
Sam Hocevar committed
96
97
98
 * in case of failure. Also, the thread system is initialized.
 *****************************************************************************/
int VLC_Create( void )
99
{
zorglub's avatar
zorglub committed
100
101
102
    libvlc_int_t *p_object = libvlc_InternalCreate();
    if( p_object ) return p_object->i_object_id;
    return VLC_ENOOBJ;
103
104
}

105
106
107
108
109
110
111
#define LIBVLC_FUNC \
    libvlc_int_t * p_libvlc = vlc_current_object( i_object ); \
    if( !p_libvlc ) return VLC_ENOOBJ;
#define LIBVLC_FUNC_END \
    if( i_object ) vlc_object_release( p_libvlc );


112
/*****************************************************************************
zorglub's avatar
zorglub committed
113
 * VLC_Init: initialize a libvlc instance
114
 *****************************************************************************
zorglub's avatar
zorglub committed
115
 * This function initializes a previously allocated libvlc instance:
116
117
118
119
120
 *  - CPU detection
 *  - gettext initialization
 *  - message queue, module bank and playlist initialization
 *  - configuration and commandline parsing
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
121
int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
122
{
zorglub's avatar
zorglub committed
123
    int i_ret;
124
    LIBVLC_FUNC;
zorglub's avatar
zorglub committed
125
    i_ret = libvlc_InternalInit( p_libvlc, i_argc, ppsz_argv );
126
    LIBVLC_FUNC_END;
zorglub's avatar
zorglub committed
127
    return i_ret;
128
129
130
}

/*****************************************************************************
Sam Hocevar's avatar
Sam Hocevar committed
131
 * VLC_AddIntf: add an interface
132
133
 *****************************************************************************
 * This function opens an interface plugin and runs it. If b_block is set
Sam Hocevar's avatar
Sam Hocevar committed
134
135
 * to 0, VLC_AddIntf will return immediately and let the interface run in a
 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
136
137
 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
 * the playlist when it is completely initialised.
138
 *****************************************************************************/
139
140
int VLC_AddIntf( int i_object, char const *psz_module,
                 vlc_bool_t b_block, vlc_bool_t b_play )
141
{
zorglub's avatar
zorglub committed
142
143
144
145
146
147
    int i_ret;
    LIBVLC_FUNC;
    i_ret = libvlc_InternalAddIntf( p_libvlc, psz_module, b_block, b_play,
                                    0, NULL );
    LIBVLC_FUNC_END;
    return i_ret;
148
149
}

150

151
/*****************************************************************************
hartman's avatar
hartman committed
152
153
154
155
156
157
158
 * VLC_Die: ask vlc to die.
 *****************************************************************************
 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
 *****************************************************************************/
int VLC_Die( int i_object )
{
159
    LIBVLC_FUNC;
160
    p_libvlc->b_die = VLC_TRUE;
161
    LIBVLC_FUNC_END;
hartman's avatar
hartman committed
162
163
164
165
166
167
168
169
    return VLC_SUCCESS;
}

/*****************************************************************************
 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
 *****************************************************************************/
int VLC_CleanUp( int i_object )
{
zorglub's avatar
zorglub committed
170
    int i_ret;
171
    LIBVLC_FUNC;
zorglub's avatar
zorglub committed
172
    i_ret = libvlc_InternalCleanup( p_libvlc );
173
    LIBVLC_FUNC_END;
zorglub's avatar
zorglub committed
174
    return i_ret;
hartman's avatar
hartman committed
175
176
177
178
}

/*****************************************************************************
 * VLC_Destroy: Destroy everything.
179
 *****************************************************************************
180
 * This function requests the running threads to finish, waits for their
181
182
 * termination, and destroys their structure.
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
183
int VLC_Destroy( int i_object )
184
{
185
    LIBVLC_FUNC;
zorglub's avatar
zorglub committed
186
    return libvlc_InternalDestroy( p_libvlc, VLC_TRUE );
187
188
}

189
/*****************************************************************************
hartman's avatar
hartman committed
190
 * VLC_VariableSet: set a vlc variable
191
 *****************************************************************************/
hartman's avatar
hartman committed
192
int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
193
{
gbazin's avatar
   
gbazin committed
194
    int i_ret;
195
    LIBVLC_FUNC;
196

Sam Hocevar's avatar
Sam Hocevar committed
197
198
199
    /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
     * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
    if( !strncmp( psz_var, "conf::", 6 ) )
200
    {
Sam Hocevar's avatar
Sam Hocevar committed
201
        module_config_t *p_item;
202
        char const *psz_newvar = psz_var + 6;
203

204
        p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
205

Sam Hocevar's avatar
Sam Hocevar committed
206
        if( p_item )
207
        {
Sam Hocevar's avatar
Sam Hocevar committed
208
            switch( p_item->i_type )
209
            {
Sam Hocevar's avatar
Sam Hocevar committed
210
                case CONFIG_ITEM_BOOL:
211
                    config_PutInt( p_libvlc, psz_newvar, value.b_bool );
Sam Hocevar's avatar
Sam Hocevar committed
212
213
                    break;
                case CONFIG_ITEM_INTEGER:
214
                    config_PutInt( p_libvlc, psz_newvar, value.i_int );
Sam Hocevar's avatar
Sam Hocevar committed
215
216
                    break;
                case CONFIG_ITEM_FLOAT:
217
                    config_PutFloat( p_libvlc, psz_newvar, value.f_float );
Sam Hocevar's avatar
Sam Hocevar committed
218
219
                    break;
                default:
220
                    config_PutPsz( p_libvlc, psz_newvar, value.psz_string );
Sam Hocevar's avatar
Sam Hocevar committed
221
                    break;
222
            }
223
            if( i_object ) vlc_object_release( p_libvlc );
Sam Hocevar's avatar
Sam Hocevar committed
224
            return VLC_SUCCESS;
225
226
227
        }
    }

228
    i_ret = var_Set( p_libvlc, psz_var, value );
gbazin's avatar
   
gbazin committed
229

230
    LIBVLC_FUNC_END;
gbazin's avatar
   
gbazin committed
231
    return i_ret;
Sam Hocevar's avatar
Sam Hocevar committed
232
233
234
}

/*****************************************************************************
hartman's avatar
hartman committed
235
 * VLC_VariableGet: get a vlc variable
Sam Hocevar's avatar
Sam Hocevar committed
236
 *****************************************************************************/
237
int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
Sam Hocevar's avatar
Sam Hocevar committed
238
{
gbazin's avatar
   
gbazin committed
239
    int i_ret;
240
    LIBVLC_FUNC;
241
    i_ret = var_Get( p_libvlc , psz_var, p_value );
242
    LIBVLC_FUNC_END;
gbazin's avatar
   
gbazin committed
243
    return i_ret;
244
245
}

246
247
248
249
250
251
/*****************************************************************************
 * VLC_VariableType: get a vlc variable type
 *****************************************************************************/
int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
{
    int i_type;
252
    LIBVLC_FUNC;
253
254
255
256
257
258
259
    /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
     * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
    if( !strncmp( psz_var, "conf::", 6 ) )
    {
        module_config_t *p_item;
        char const *psz_newvar = psz_var + 6;

260
        p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

        if( p_item )
        {
            switch( p_item->i_type )
            {
                case CONFIG_ITEM_BOOL:
                    i_type = VLC_VAR_BOOL;
                    break;
                case CONFIG_ITEM_INTEGER:
                    i_type = VLC_VAR_INTEGER;
                    break;
                case CONFIG_ITEM_FLOAT:
                    i_type = VLC_VAR_FLOAT;
                    break;
                default:
                    i_type = VLC_VAR_STRING;
                    break;
            }
        }
        else
            i_type = 0;
    }
    else
284
        i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
285

286
    LIBVLC_FUNC_END;
287
288
289
290
291
292
293
294
295

    if( i_type > 0 )
    {
        *pi_type = i_type;
        return VLC_SUCCESS;
    }
    return VLC_ENOVAR;
}

296
297
298
299
300
301
302
303
304
#define LIBVLC_PLAYLIST_FUNC \
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
    if( !p_libvlc || !p_libvlc->p_playlist ) return VLC_ENOOBJ; \
    vlc_object_yield( p_libvlc->p_playlist );

#define LIBVLC_PLAYLIST_FUNC_END \
    vlc_object_release( p_libvlc->p_playlist ); \
    if( i_object ) vlc_object_release( p_libvlc );

305
/*****************************************************************************
hartman's avatar
hartman committed
306
307
 * VLC_AddTarget: adds a target for playing.
 *****************************************************************************
308
 * This function adds psz_target to the playlist
309
 *****************************************************************************/
310

hartman's avatar
hartman committed
311
312
313
int VLC_AddTarget( int i_object, char const *psz_target,
                   char const **ppsz_options, int i_options,
                   int i_mode, int i_pos )
314
{
hartman's avatar
hartman committed
315
    int i_err;
316
317
318
319
320
    LIBVLC_PLAYLIST_FUNC;
    i_err = playlist_PlaylistAddExt( p_libvlc->p_playlist, psz_target,
                                     psz_target,  i_mode, i_pos, -1,
                                     ppsz_options, i_options );
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
321
    return i_err;
322
323
324
}

/*****************************************************************************
325
 * VLC_Play: play the playlist
326
 *****************************************************************************/
hartman's avatar
hartman committed
327
int VLC_Play( int i_object )
328
{
329
330
331
    LIBVLC_PLAYLIST_FUNC;
    playlist_Play( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
332
    return VLC_SUCCESS;
333
334
}

335
/*****************************************************************************
hartman's avatar
hartman committed
336
 * VLC_Pause: toggle pause
337
 *****************************************************************************/
hartman's avatar
hartman committed
338
int VLC_Pause( int i_object )
339
{
340
341
342
    LIBVLC_PLAYLIST_FUNC;
    playlist_Pause( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
343
    return VLC_SUCCESS;
344
345
346
}

/*****************************************************************************
347
 * VLC_Stop: stop playback
348
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
349
int VLC_Stop( int i_object )
350
{
351
352
353
    LIBVLC_PLAYLIST_FUNC;
    playlist_Stop( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
354
    return VLC_SUCCESS;
hartman's avatar
hartman committed
355
}
zorglub's avatar
zorglub committed
356

hartman's avatar
hartman committed
357
358
359
360
361
362
363
/*****************************************************************************
 * VLC_IsPlaying: Query for Playlist Status
 *****************************************************************************/
vlc_bool_t VLC_IsPlaying( int i_object )
{
    vlc_bool_t   b_playing;

364
365
    LIBVLC_PLAYLIST_FUNC;
    if( p_libvlc->p_playlist->p_input )
hartman's avatar
hartman committed
366
    {
367
        vlc_value_t  val;
368
        var_Get( p_libvlc->p_playlist->p_input, "state", &val );
369
370
371
372
        b_playing = ( val.i_int == PLAYING_S );
    }
    else
    {
373
        b_playing = playlist_IsPlaying( p_libvlc->p_playlist );
hartman's avatar
hartman committed
374
    }
375
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
    return b_playing;
}

/**
 * Get the current position in a input
 *
 * Return the current position as a float
 * \note For some inputs, this will be unknown.
 *
 * \param i_object a vlc object id
 * \return a float in the range of 0.0 - 1.0
 */
float VLC_PositionGet( int i_object )
{
    input_thread_t *p_input;
    vlc_value_t val;
zorglub's avatar
zorglub committed
392
    LIBVLC_FUNC;
hartman's avatar
hartman committed
393

394
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
395
396
397

    if( !p_input )
    {
398
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
399
400
401
402
403
404
        return VLC_ENOOBJ;
    }

    var_Get( p_input, "position", &val );
    vlc_object_release( p_input );

zorglub's avatar
zorglub committed
405
    LIBVLC_FUNC_END;
hartman's avatar
hartman committed
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
    return val.f_float;
}

/**
 * Set the current position in a input
 *
 * Set the current position in a input and then return
 * the current position as a float.
 * \note For some inputs, this will be unknown.
 *
 * \param i_object a vlc object id
 * \param i_position a float in the range of 0.0 - 1.0
 * \return a float in the range of 0.0 - 1.0
 */
float VLC_PositionSet( int i_object, float i_position )
{
    input_thread_t *p_input;
    vlc_value_t val;
424
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
hartman's avatar
hartman committed
425
426

    /* Check that the handle is valid */
427
    if( !p_libvlc )
hartman's avatar
hartman committed
428
429
430
431
    {
        return VLC_ENOOBJ;
    }

432
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
433

hartman's avatar
hartman committed
434
435
    if( !p_input )
    {
436
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
437
438
439
440
441
442
443
444
        return VLC_ENOOBJ;
    }

    val.f_float = i_position;
    var_Set( p_input, "position", val );
    var_Get( p_input, "position", &val );
    vlc_object_release( p_input );

445
    if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
    return val.f_float;
}

/**
 * Get the current position in a input
 *
 * Return the current position in seconds from the start.
 * \note For some inputs, this will be unknown.
 *
 * \param i_object a vlc object id
 * \return the offset from 0:00 in seconds
 */
int VLC_TimeGet( int i_object )
{
    input_thread_t *p_input;
    vlc_value_t val;
462
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
hartman's avatar
hartman committed
463
464

    /* Check that the handle is valid */
465
    if( !p_libvlc )
hartman's avatar
hartman committed
466
467
468
469
    {
        return VLC_ENOOBJ;
    }

470
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
471
472
473

    if( !p_input )
    {
474
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
475
476
477
478
479
480
        return VLC_ENOOBJ;
    }

    var_Get( p_input, "time", &val );
    vlc_object_release( p_input );

481
    if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
    return val.i_time  / 1000000;
}

/**
 * Seek to a position in the current input
 *
 * Seek i_seconds in the current input. If b_relative is set,
 * then the seek will be relative to the current position, otherwise
 * it will seek to i_seconds from the beginning of the input.
 * \note For some inputs, this will be unknown.
 *
 * \param i_object a vlc object id
 * \param i_seconds seconds from current position or from beginning of input
 * \param b_relative seek relative from current position
 * \return VLC_SUCCESS on success
 */
int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
{
    input_thread_t *p_input;
    vlc_value_t val;
502
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
hartman's avatar
hartman committed
503
504

    /* Check that the handle is valid */
505
    if( !p_libvlc )
hartman's avatar
hartman committed
506
507
508
509
    {
        return VLC_ENOOBJ;
    }

510
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
511
512
513

    if( !p_input )
    {
514
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
515
516
517
518
519
        return VLC_ENOOBJ;
    }

    if( b_relative )
    {
520
521
        val.i_time = i_seconds;
        val.i_time = val.i_time * 1000000L;
hartman's avatar
hartman committed
522
523
524
525
        var_Set( p_input, "time-offset", val );
    }
    else
    {
526
527
        val.i_time = i_seconds;
        val.i_time = val.i_time * 1000000L;
hartman's avatar
hartman committed
528
529
530
531
        var_Set( p_input, "time", val );
    }
    vlc_object_release( p_input );

532
    if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    return VLC_SUCCESS;
}

/**
 * Get the total length of a input
 *
 * Return the total length in seconds from the current input.
 * \note For some inputs, this will be unknown.
 *
 * \param i_object a vlc object id
 * \return the length in seconds
 */
int VLC_LengthGet( int i_object )
{
    input_thread_t *p_input;
    vlc_value_t val;
549
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
hartman's avatar
hartman committed
550
551

    /* Check that the handle is valid */
552
    if( !p_libvlc )
hartman's avatar
hartman committed
553
554
555
556
    {
        return VLC_ENOOBJ;
    }

557
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
558
559
560

    if( !p_input )
    {
561
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
562
563
564
565
566
567
        return VLC_ENOOBJ;
    }

    var_Get( p_input, "length", &val );
    vlc_object_release( p_input );

568
    if( i_object ) vlc_object_release( p_libvlc );
569
    return val.i_time  / 1000000L;
hartman's avatar
hartman committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
}

/**
 * Play the input faster than realtime
 *
 * 2x, 4x, 8x faster than realtime
 * \note For some inputs, this will be impossible.
 *
 * \param i_object a vlc object id
 * \return the current speedrate
 */
float VLC_SpeedFaster( int i_object )
{
    input_thread_t *p_input;
    vlc_value_t val;
585
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
hartman's avatar
hartman committed
586
587

    /* Check that the handle is valid */
588
    if( !p_libvlc )
hartman's avatar
hartman committed
589
590
591
592
    {
        return VLC_ENOOBJ;
    }

593
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
594
595
596

    if( !p_input )
    {
597
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
598
599
600
601
602
603
604
605
        return VLC_ENOOBJ;
    }

    val.b_bool = VLC_TRUE;
    var_Set( p_input, "rate-faster", val );
    var_Get( p_input, "rate", &val );
    vlc_object_release( p_input );

606
    if( i_object ) vlc_object_release( p_libvlc );
Laurent Aimar's avatar
Laurent Aimar committed
607
    return val.f_float / INPUT_RATE_DEFAULT;
hartman's avatar
hartman committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
}

/**
 * Play the input slower than realtime
 *
 * 1/2x, 1/4x, 1/8x slower than realtime
 * \note For some inputs, this will be impossible.
 *
 * \param i_object a vlc object id
 * \return the current speedrate
 */
float VLC_SpeedSlower( int i_object )
{
    input_thread_t *p_input;
    vlc_value_t val;
623
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
hartman's avatar
hartman committed
624
625

    /* Check that the handle is valid */
626
    if( !p_libvlc )
hartman's avatar
hartman committed
627
628
629
630
    {
        return VLC_ENOOBJ;
    }

631
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
hartman's avatar
hartman committed
632
633
634

    if( !p_input )
    {
635
        if( i_object ) vlc_object_release( p_libvlc );
hartman's avatar
hartman committed
636
637
638
639
640
641
642
643
        return VLC_ENOOBJ;
    }

    val.b_bool = VLC_TRUE;
    var_Set( p_input, "rate-slower", val );
    var_Get( p_input, "rate", &val );
    vlc_object_release( p_input );

644
    if( i_object ) vlc_object_release( p_libvlc );
Laurent Aimar's avatar
Laurent Aimar committed
645
    return val.f_float / INPUT_RATE_DEFAULT;
hartman's avatar
hartman committed
646
647
648
649
650
651
652
653
654
655
656
657
658
}

/**
 * Return the current playlist item
 *
 * Returns the index of the playlistitem that is currently selected for play.
 * This is valid even if nothing is currently playing.
 *
 * \param i_object a vlc object id
 * \return the current index
 */
int VLC_PlaylistIndex( int i_object )
{
659
660
    printf( "This function is deprecated and should not be used anymore" );
    return -1;
hartman's avatar
hartman committed
661
}
hartman's avatar
hartman committed
662

hartman's avatar
hartman committed
663
/**
zorglub's avatar
zorglub committed
664
 * Total number of items in the playlist
hartman's avatar
hartman committed
665
666
667
668
669
670
671
 *
 * \param i_object a vlc object id
 * \return amount of playlist items
 */
int VLC_PlaylistNumberOfItems( int i_object )
{
    int i_size;
zorglub's avatar
zorglub committed
672
673
674
    LIBVLC_PLAYLIST_FUNC;
    i_size = p_libvlc->p_playlist->i_size;
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
675
676
677
678
    return i_size;
}

/**
zorglub's avatar
zorglub committed
679
 * Go to next playlist item
hartman's avatar
hartman committed
680
681
682
683
684
 * \param i_object a vlc object id
 * \return VLC_SUCCESS on success
 */
int VLC_PlaylistNext( int i_object )
{
zorglub's avatar
zorglub committed
685
686
687
    LIBVLC_PLAYLIST_FUNC;
    playlist_Next( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
688
689
690
691
    return VLC_SUCCESS;
}

/**
zorglub's avatar
zorglub committed
692
 * Go to previous playlist item
hartman's avatar
hartman committed
693
694
695
696
697
 * \param i_object a vlc object id
 * \return VLC_SUCCESS on success
 */
int VLC_PlaylistPrev( int i_object )
{
zorglub's avatar
zorglub committed
698
699
700
    LIBVLC_PLAYLIST_FUNC;
    playlist_Prev( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
hartman's avatar
hartman committed
701
    return VLC_SUCCESS;
702
703
}

zorglub's avatar
zorglub committed
704
705
706
/**
 * Empty the playlist
 */
hartman's avatar
hartman committed
707
int VLC_PlaylistClear( int i_object )
708
{
zorglub's avatar
zorglub committed
709
710
711
    LIBVLC_PLAYLIST_FUNC;
    playlist_Clear( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
712
    return VLC_SUCCESS;
713
714
}

hartman's avatar
hartman committed
715
716
717
718
719
720
721
722
723
/**
 * Change the volume
 *
 * \param i_object a vlc object id
 * \param i_volume something in a range from 0-200
 * \return the new volume (range 0-200 %)
 */
int VLC_VolumeSet( int i_object, int i_volume )
{
724
    audio_volume_t i_vol = 0;
zorglub's avatar
zorglub committed
725
    LIBVLC_FUNC;
hartman's avatar
hartman committed
726

727
    if( i_volume >= 0 && i_volume <= 200 )
hartman's avatar
hartman committed
728
729
    {
        i_vol = i_volume * AOUT_VOLUME_MAX / 200;
730
        aout_VolumeSet( p_libvlc, i_vol );
hartman's avatar
hartman committed
731
    }
zorglub's avatar
zorglub committed
732
    LIBVLC_FUNC_END;
hartman's avatar
hartman committed
733
734
735
736
737
738
739
740
741
742
743
744
745
746
    return i_vol * 200 / AOUT_VOLUME_MAX;
}

/**
 * Get the current volume
 *
 * Retrieve the current volume.
 *
 * \param i_object a vlc object id
 * \return the current volume (range 0-200 %)
 */
int VLC_VolumeGet( int i_object )
{
    audio_volume_t i_volume;
zorglub's avatar
zorglub committed
747
    LIBVLC_FUNC;
748
    aout_VolumeGet( p_libvlc, &i_volume );
zorglub's avatar
zorglub committed
749
    LIBVLC_FUNC_END;
hartman's avatar
hartman committed
750
751
752
753
754
755
756
757
758
759
760
    return i_volume*200/AOUT_VOLUME_MAX;
}

/**
 * Mute/Unmute the volume
 *
 * \param i_object a vlc object id
 * \return VLC_SUCCESS on success
 */
int VLC_VolumeMute( int i_object )
{
zorglub's avatar
zorglub committed
761
    LIBVLC_FUNC;
762
    aout_VolumeMute( p_libvlc, NULL );
zorglub's avatar
zorglub committed
763
    LIBVLC_FUNC_END;
hartman's avatar
hartman committed
764
765
766
    return VLC_SUCCESS;
}

767
/*****************************************************************************
Sam Hocevar's avatar
Sam Hocevar committed
768
 * VLC_FullScreen: toggle fullscreen mode
769
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
770
int VLC_FullScreen( int i_object )
771
772
{
    vout_thread_t *p_vout;
zorglub's avatar
zorglub committed
773
    LIBVLC_FUNC;
774
    p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
775
776
777

    if( !p_vout )
    {
778
        if( i_object ) vlc_object_release( p_libvlc );
779
        return VLC_ENOOBJ;
780
781
782
783
    }

    p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
    vlc_object_release( p_vout );
zorglub's avatar
zorglub committed
784
    LIBVLC_FUNC_END;
hartman's avatar
hartman committed
785
786
    return VLC_SUCCESS;
}