libvlc.c 22.7 KB
Newer Older
1
/*****************************************************************************
Clément Stenac's avatar
Clément Stenac committed
2
 * libvlc.c: Implementation of the old libvlc API
3
 *****************************************************************************
4
 * Copyright (C) 1998-2007 the VideoLAN team
5
 * $Id$
6 7 8
 *
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
9
 *          Gildas Bazin <gbazin@videolan.org>
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
Antoine Cellerier's avatar
Antoine Cellerier 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 39 40 41
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

42 43
#include <vlc/vlc.h>

Clément Stenac's avatar
Clément Stenac committed
44
#include "control/libvlc_internal.h"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
45
#include "libvlc.h"
46

47
#include <vlc_playlist.h>
48

Clément Stenac's avatar
Clément Stenac committed
49 50
#include <vlc_aout.h>
#include <vlc_vout.h>
51 52

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

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

72 73
DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
Christophe Mutricy's avatar
Typo  
Christophe Mutricy committed
74
DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
75 76 77
DECLARE_VLC_VERSION( Compiler, COMPILER );

extern const char psz_vlc_changeset[];
78
const char* VLC_Changeset( void )
79 80 81
{
    return psz_vlc_changeset;
}
82

83 84 85 86 87 88 89 90 91 92
/*****************************************************************************
 * 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
93
/*****************************************************************************
Clément Stenac's avatar
Clément Stenac committed
94
 * VLC_Create: allocate a libvlc instance and intialize global libvlc stuff if needed
Sam Hocevar's avatar
Sam Hocevar committed
95
 *****************************************************************************
Clément Stenac's avatar
Clément Stenac committed
96
 * This function allocates a libvlc instance and returns a negative value
Sam Hocevar's avatar
Sam Hocevar committed
97 98 99
 * in case of failure. Also, the thread system is initialized.
 *****************************************************************************/
int VLC_Create( void )
100
{
Clément Stenac's avatar
Clément Stenac committed
101 102 103
    libvlc_int_t *p_object = libvlc_InternalCreate();
    if( p_object ) return p_object->i_object_id;
    return VLC_ENOOBJ;
104 105
}

106 107 108 109 110 111 112
#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 );


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

/*****************************************************************************
Sam Hocevar's avatar
Sam Hocevar committed
132
 * VLC_AddIntf: add an interface
133 134
 *****************************************************************************
 * This function opens an interface plugin and runs it. If b_block is set
Sam Hocevar's avatar
Sam Hocevar committed
135 136
 * 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
137 138
 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
 * the playlist when it is completely initialised.
139
 *****************************************************************************/
140
int VLC_AddIntf( int i_object, char const *psz_module,
141
                 bool b_block, bool b_play )
142
{
Clément Stenac's avatar
Clément Stenac committed
143 144 145 146 147 148
    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;
149 150
}

151

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

/*****************************************************************************
 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
 *****************************************************************************/
int VLC_CleanUp( int i_object )
{
Clément Stenac's avatar
Clément Stenac committed
171
    int i_ret;
172
    LIBVLC_FUNC;
Clément Stenac's avatar
Clément Stenac committed
173
    i_ret = libvlc_InternalCleanup( p_libvlc );
174
    LIBVLC_FUNC_END;
Clément Stenac's avatar
Clément Stenac committed
175
    return i_ret;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
176 177 178 179
}

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

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

Sam Hocevar's avatar
Sam Hocevar committed
198 199 200
    /* 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 ) )
201
    {
Sam Hocevar's avatar
Sam Hocevar committed
202
        module_config_t *p_item;
203
        char const *psz_newvar = psz_var + 6;
204

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

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

229
    i_ret = var_Set( p_libvlc, psz_var, value );
Gildas Bazin's avatar
 
Gildas Bazin committed
230

231
    LIBVLC_FUNC_END;
Gildas Bazin's avatar
 
Gildas Bazin committed
232
    return i_ret;
Sam Hocevar's avatar
Sam Hocevar committed
233 234 235
}

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

247 248 249 250 251 252
/*****************************************************************************
 * VLC_VariableType: get a vlc variable type
 *****************************************************************************/
int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
{
    int i_type;
253
    LIBVLC_FUNC;
254 255 256 257 258 259 260
    /* 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;

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

        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
285
        i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
286

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

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

297 298
#define LIBVLC_PLAYLIST_FUNC \
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
299 300 301
    if( !p_libvlc ) return VLC_ENOOBJ; \
    playlist_t *p_playlist = pl_Yield( p_libvlc ); \
    if( !p_playlist ) return VLC_ENOOBJ
302 303

#define LIBVLC_PLAYLIST_FUNC_END \
304
    pl_Release( p_libvlc ); \
305 306
    if( i_object ) vlc_object_release( p_libvlc );

307
/*****************************************************************************
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
308 309
 * VLC_AddTarget: adds a target for playing.
 *****************************************************************************
310
 * This function adds psz_target to the playlist
311
 *****************************************************************************/
312

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
313 314 315
int VLC_AddTarget( int i_object, char const *psz_target,
                   char const **ppsz_options, int i_options,
                   int i_mode, int i_pos )
316
{
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
317
    int i_err;
318
    LIBVLC_PLAYLIST_FUNC;
319
    i_err = playlist_AddExt( p_playlist, psz_target,
320
                             NULL,  i_mode, i_pos, -1,
321
                             ppsz_options, i_options, true, false );
322
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
323
    return i_err;
324 325 326
}

/*****************************************************************************
327
 * VLC_Play: play the playlist
328
 *****************************************************************************/
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
329
int VLC_Play( int i_object )
330
{
331
    LIBVLC_PLAYLIST_FUNC;
332
    playlist_Play( p_playlist );
333
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
334
    return VLC_SUCCESS;
335 336
}

337
/*****************************************************************************
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
338
 * VLC_Pause: toggle pause
339
 *****************************************************************************/
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
340
int VLC_Pause( int i_object )
341
{
342
    LIBVLC_PLAYLIST_FUNC;
343
    playlist_Pause( p_playlist );
344
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
345
    return VLC_SUCCESS;
346 347 348
}

/*****************************************************************************
349
 * VLC_Stop: stop playback
350
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
351
int VLC_Stop( int i_object )
352
{
353
    LIBVLC_PLAYLIST_FUNC;
354
    playlist_Stop( p_playlist );
355
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
356
    return VLC_SUCCESS;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
357
}
Clément Stenac's avatar
Clément Stenac committed
358

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
359 360 361
/*****************************************************************************
 * VLC_IsPlaying: Query for Playlist Status
 *****************************************************************************/
362
bool VLC_IsPlaying( int i_object )
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
363
{
364
    bool   b_playing;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
365

366
    LIBVLC_PLAYLIST_FUNC;
367
    if( p_playlist->p_input )
368
    {
369
        vlc_value_t  val;
370
        var_Get( p_playlist->p_input, "state", &val );
371 372 373 374
        b_playing = ( val.i_int == PLAYING_S );
    }
    else
    {
375
        b_playing = playlist_IsPlaying( p_playlist );
376
    }
377
    LIBVLC_PLAYLIST_FUNC_END;
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
    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;
Clément Stenac's avatar
Clément Stenac committed
394
    LIBVLC_FUNC;
395

396
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
397 398 399

    if( !p_input )
    {
400
        if( i_object ) vlc_object_release( p_libvlc );
401 402 403 404 405 406
        return VLC_ENOOBJ;
    }

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

Clément Stenac's avatar
Clément Stenac committed
407
    LIBVLC_FUNC_END;
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    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;
426
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
427 428

    /* Check that the handle is valid */
429
    if( !p_libvlc )
430 431 432 433
    {
        return VLC_ENOOBJ;
    }

434
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
435

436 437
    if( !p_input )
    {
438
        if( i_object ) vlc_object_release( p_libvlc );
439 440 441 442 443 444 445 446
        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 );

447
    if( i_object ) vlc_object_release( p_libvlc );
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
    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;
464
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
465 466

    /* Check that the handle is valid */
467
    if( !p_libvlc )
468 469 470 471
    {
        return VLC_ENOOBJ;
    }

472
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
473 474 475

    if( !p_input )
    {
476
        if( i_object ) vlc_object_release( p_libvlc );
477 478 479 480 481 482
        return VLC_ENOOBJ;
    }

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

483
    if( i_object ) vlc_object_release( p_libvlc );
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
    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
 */
500
int VLC_TimeSet( int i_object, int i_seconds, bool b_relative )
501 502 503
{
    input_thread_t *p_input;
    vlc_value_t val;
504
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
505 506

    /* Check that the handle is valid */
507
    if( !p_libvlc )
508 509 510 511
    {
        return VLC_ENOOBJ;
    }

512
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
513 514 515

    if( !p_input )
    {
516
        if( i_object ) vlc_object_release( p_libvlc );
517 518 519 520 521
        return VLC_ENOOBJ;
    }

    if( b_relative )
    {
522 523
        val.i_time = i_seconds;
        val.i_time = val.i_time * 1000000L;
524 525 526 527
        var_Set( p_input, "time-offset", val );
    }
    else
    {
528 529
        val.i_time = i_seconds;
        val.i_time = val.i_time * 1000000L;
530 531 532 533
        var_Set( p_input, "time", val );
    }
    vlc_object_release( p_input );

534
    if( i_object ) vlc_object_release( p_libvlc );
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    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;
551
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
552 553

    /* Check that the handle is valid */
554
    if( !p_libvlc )
555 556 557 558
    {
        return VLC_ENOOBJ;
    }

559
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
560 561 562

    if( !p_input )
    {
563
        if( i_object ) vlc_object_release( p_libvlc );
564 565 566 567 568 569
        return VLC_ENOOBJ;
    }

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

570
    if( i_object ) vlc_object_release( p_libvlc );
571
    return val.i_time  / 1000000L;
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
}

/**
 * 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;
587
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
588 589

    /* Check that the handle is valid */
590
    if( !p_libvlc )
591 592 593 594
    {
        return VLC_ENOOBJ;
    }

595
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
596 597 598

    if( !p_input )
    {
599
        if( i_object ) vlc_object_release( p_libvlc );
600 601 602
        return VLC_ENOOBJ;
    }

603
    val.b_bool = true;
604 605 606 607
    var_Set( p_input, "rate-faster", val );
    var_Get( p_input, "rate", &val );
    vlc_object_release( p_input );

608
    if( i_object ) vlc_object_release( p_libvlc );
609
    return val.f_float / INPUT_RATE_DEFAULT;
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
}

/**
 * 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;
625
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
626 627

    /* Check that the handle is valid */
628
    if( !p_libvlc )
629 630 631 632
    {
        return VLC_ENOOBJ;
    }

633
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
634 635 636

    if( !p_input )
    {
637
        if( i_object ) vlc_object_release( p_libvlc );
638 639 640
        return VLC_ENOOBJ;
    }

641
    val.b_bool = true;
642 643 644 645
    var_Set( p_input, "rate-slower", val );
    var_Get( p_input, "rate", &val );
    vlc_object_release( p_input );

646
    if( i_object ) vlc_object_release( p_libvlc );
647
    return val.f_float / INPUT_RATE_DEFAULT;
648 649 650 651 652 653 654 655 656 657 658 659 660
}

/**
 * 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 )
{
661
    (void)i_object;
662 663
    printf( "This function is deprecated and should not be used anymore" );
    return -1;
664
}
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
665

666
/**
Clément Stenac's avatar
Clément Stenac committed
667
 * Total number of items in the playlist
668 669 670 671 672 673 674
 *
 * \param i_object a vlc object id
 * \return amount of playlist items
 */
int VLC_PlaylistNumberOfItems( int i_object )
{
    int i_size;
Clément Stenac's avatar
Clément Stenac committed
675
    LIBVLC_PLAYLIST_FUNC;
676
    i_size = p_playlist->items.i_size;
Clément Stenac's avatar
Clément Stenac committed
677
    LIBVLC_PLAYLIST_FUNC_END;
678 679 680 681
    return i_size;
}

/**
Clément Stenac's avatar
Clément Stenac committed
682
 * Go to next playlist item
683 684 685 686 687
 * \param i_object a vlc object id
 * \return VLC_SUCCESS on success
 */
int VLC_PlaylistNext( int i_object )
{
Clément Stenac's avatar
Clément Stenac committed
688
    LIBVLC_PLAYLIST_FUNC;
689
    playlist_Next( p_playlist );
Clément Stenac's avatar
Clément Stenac committed
690
    LIBVLC_PLAYLIST_FUNC_END;
691 692 693 694
    return VLC_SUCCESS;
}

/**
Clément Stenac's avatar
Clément Stenac committed
695
 * Go to previous playlist item
696 697 698 699 700
 * \param i_object a vlc object id
 * \return VLC_SUCCESS on success
 */
int VLC_PlaylistPrev( int i_object )
{
Clément Stenac's avatar
Clément Stenac committed
701
    LIBVLC_PLAYLIST_FUNC;
702
    playlist_Prev( p_playlist );
Clément Stenac's avatar
Clément Stenac committed
703
    LIBVLC_PLAYLIST_FUNC_END;
704
    return VLC_SUCCESS;
705 706
}

Clément Stenac's avatar
Clément Stenac committed
707 708 709
/**
 * Empty the playlist
 */
710
int VLC_PlaylistClear( int i_object )
711
{
Clément Stenac's avatar
Clément Stenac committed
712
    LIBVLC_PLAYLIST_FUNC;
713
    playlist_Clear( p_playlist, true );
Clément Stenac's avatar
Clément Stenac committed
714
    LIBVLC_PLAYLIST_FUNC_END;
715
    return VLC_SUCCESS;
716 717
}

718 719 720 721 722 723 724 725 726
/**
 * 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 )
{
727
    audio_volume_t i_vol = 0;
Clément Stenac's avatar
Clément Stenac committed
728
    LIBVLC_FUNC;
729

730
    if( i_volume >= 0 && i_volume <= 200 )
731 732
    {
        i_vol = i_volume * AOUT_VOLUME_MAX / 200;
733
        aout_VolumeSet( p_libvlc, i_vol );
734
    }
Clément Stenac's avatar
Clément Stenac committed
735
    LIBVLC_FUNC_END;
736 737 738 739 740 741 742 743 744 745 746 747 748 749
    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;
Clément Stenac's avatar
Clément Stenac committed
750
    LIBVLC_FUNC;
751
    aout_VolumeGet( p_libvlc, &i_volume );
Clément Stenac's avatar
Clément Stenac committed
752
    LIBVLC_FUNC_END;
753 754 755 756 757 758 759 760 761 762 763
    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 )
{
Clément Stenac's avatar
Clément Stenac committed
764
    LIBVLC_FUNC;
765
    aout_VolumeMute( p_libvlc, NULL );
Clément Stenac's avatar
Clément Stenac committed
766
    LIBVLC_FUNC_END;
767 768 769
    return VLC_SUCCESS;
}

770
/*****************************************************************************
Sam Hocevar's avatar
Sam Hocevar committed
771
 * VLC_FullScreen: toggle fullscreen mode
772
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
773
int VLC_FullScreen( int i_object )
774 775
{
    vout_thread_t *p_vout;
Clément Stenac's avatar
Clément Stenac committed
776
    LIBVLC_FUNC;
777
    p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
778 779 780

    if( !p_vout )
    {
781
        if( i_object ) vlc_object_release( p_libvlc );
782
        return VLC_ENOOBJ;
783 784 785 786
    }

    p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
    vlc_object_release( p_vout );
Clément Stenac's avatar
Clément Stenac committed
787
    LIBVLC_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
788 789
    return VLC_SUCCESS;
}