libvlc.c 22.8 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
#include <vlc/vlc.h>

Clément Stenac's avatar
Clément Stenac committed
40
#include "control/libvlc_internal.h"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
41
#include "libvlc.h"
42

43
#include <vlc_playlist.h>
44

Clément Stenac's avatar
Clément Stenac committed
45 46
#include <vlc_aout.h>
#include <vlc_vout.h>
47 48

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

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

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

extern const char psz_vlc_changeset[];
74
const char* VLC_Changeset( void )
75 76 77
{
    return psz_vlc_changeset;
}
78

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

102 103 104 105 106 107 108
#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 );


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

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

147

148
/*****************************************************************************
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
149 150
 * VLC_Die: ask vlc to die.
 *****************************************************************************
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
151
 * This function sets p_libvlc->b_die to VLC_TRUE, but does not do any other
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
152 153 154 155
 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
 *****************************************************************************/
int VLC_Die( int i_object )
{
156
    LIBVLC_FUNC;
157
    vlc_object_kill( p_libvlc );
158
    LIBVLC_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
159 160 161 162 163 164 165 166
    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
167
    int i_ret;
168
    LIBVLC_FUNC;
Clément Stenac's avatar
Clément Stenac committed
169
    i_ret = libvlc_InternalCleanup( p_libvlc );
170
    LIBVLC_FUNC_END;
Clément Stenac's avatar
Clément Stenac committed
171
    return i_ret;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
172 173 174 175
}

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

186
/*****************************************************************************
187
 * VLC_VariableSet: set a vlc variable
188
 *****************************************************************************/
189
int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
190
{
191
    int i_ret;
192
    LIBVLC_FUNC;
193

Sam Hocevar's avatar
Sam Hocevar committed
194 195 196
    /* 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 ) )
197
    {
Sam Hocevar's avatar
Sam Hocevar committed
198
        module_config_t *p_item;
199
        char const *psz_newvar = psz_var + 6;
200

201
        p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
202

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

225
    i_ret = var_Set( p_libvlc, psz_var, value );
226

227
    LIBVLC_FUNC_END;
228
    return i_ret;
Sam Hocevar's avatar
Sam Hocevar committed
229 230 231
}

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

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

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

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

283
    LIBVLC_FUNC_END;
284 285 286 287 288 289 290 291 292

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

293 294 295 296 297 298 299 300 301
#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 );

302
/*****************************************************************************
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
303 304
 * VLC_AddTarget: adds a target for playing.
 *****************************************************************************
305
 * This function adds psz_target to the playlist
306
 *****************************************************************************/
307

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
308 309 310
int VLC_AddTarget( int i_object, char const *psz_target,
                   char const **ppsz_options, int i_options,
                   int i_mode, int i_pos )
311
{
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
312
    int i_err;
313
    LIBVLC_PLAYLIST_FUNC;
314 315
    i_err = playlist_AddExt( p_libvlc->p_playlist, psz_target,
                             NULL,  i_mode, i_pos, -1,
316
                             ppsz_options, i_options, VLC_TRUE, VLC_FALSE );
317
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
318
    return i_err;
319 320 321
}

/*****************************************************************************
322
 * VLC_Play: play the playlist
323
 *****************************************************************************/
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
324
int VLC_Play( int i_object )
325
{
326 327 328
    LIBVLC_PLAYLIST_FUNC;
    playlist_Play( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
329
    return VLC_SUCCESS;
330 331
}

332
/*****************************************************************************
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
333
 * VLC_Pause: toggle pause
334
 *****************************************************************************/
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
335
int VLC_Pause( int i_object )
336
{
337 338 339
    LIBVLC_PLAYLIST_FUNC;
    playlist_Pause( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
340
    return VLC_SUCCESS;
341 342 343
}

/*****************************************************************************
344
 * VLC_Stop: stop playback
345
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
346
int VLC_Stop( int i_object )
347
{
348 349 350
    LIBVLC_PLAYLIST_FUNC;
    playlist_Stop( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
351
    return VLC_SUCCESS;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
352
}
Clément Stenac's avatar
Clément Stenac committed
353

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
354 355 356 357 358 359 360
/*****************************************************************************
 * VLC_IsPlaying: Query for Playlist Status
 *****************************************************************************/
vlc_bool_t VLC_IsPlaying( int i_object )
{
    vlc_bool_t   b_playing;

361 362
    LIBVLC_PLAYLIST_FUNC;
    if( p_libvlc->p_playlist->p_input )
363
    {
364
        vlc_value_t  val;
365
        var_Get( p_libvlc->p_playlist->p_input, "state", &val );
366 367 368 369
        b_playing = ( val.i_int == PLAYING_S );
    }
    else
    {
370
        b_playing = playlist_IsPlaying( p_libvlc->p_playlist );
371
    }
372
    LIBVLC_PLAYLIST_FUNC_END;
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    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
389
    LIBVLC_FUNC;
390

391
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
392 393 394

    if( !p_input )
    {
395
        if( i_object ) vlc_object_release( p_libvlc );
396 397 398 399 400 401
        return VLC_ENOOBJ;
    }

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

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

    /* Check that the handle is valid */
424
    if( !p_libvlc )
425 426 427 428
    {
        return VLC_ENOOBJ;
    }

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

431 432
    if( !p_input )
    {
433
        if( i_object ) vlc_object_release( p_libvlc );
434 435 436 437 438 439 440 441
        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 );

442
    if( i_object ) vlc_object_release( p_libvlc );
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    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;
459
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
460 461

    /* Check that the handle is valid */
462
    if( !p_libvlc )
463 464 465 466
    {
        return VLC_ENOOBJ;
    }

467
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
468 469 470

    if( !p_input )
    {
471
        if( i_object ) vlc_object_release( p_libvlc );
472 473 474 475 476 477
        return VLC_ENOOBJ;
    }

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

478
    if( i_object ) vlc_object_release( p_libvlc );
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
    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;
499
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
500 501

    /* Check that the handle is valid */
502
    if( !p_libvlc )
503 504 505 506
    {
        return VLC_ENOOBJ;
    }

507
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
508 509 510

    if( !p_input )
    {
511
        if( i_object ) vlc_object_release( p_libvlc );
512 513 514 515 516
        return VLC_ENOOBJ;
    }

    if( b_relative )
    {
517 518
        val.i_time = i_seconds;
        val.i_time = val.i_time * 1000000L;
519 520 521 522
        var_Set( p_input, "time-offset", val );
    }
    else
    {
523 524
        val.i_time = i_seconds;
        val.i_time = val.i_time * 1000000L;
525 526 527 528
        var_Set( p_input, "time", val );
    }
    vlc_object_release( p_input );

529
    if( i_object ) vlc_object_release( p_libvlc );
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
    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;
546
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
547 548

    /* Check that the handle is valid */
549
    if( !p_libvlc )
550 551 552 553
    {
        return VLC_ENOOBJ;
    }

554
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
555 556 557

    if( !p_input )
    {
558
        if( i_object ) vlc_object_release( p_libvlc );
559 560 561 562 563 564
        return VLC_ENOOBJ;
    }

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

565
    if( i_object ) vlc_object_release( p_libvlc );
566
    return val.i_time  / 1000000L;
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
}

/**
 * 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;
582
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
583 584

    /* Check that the handle is valid */
585
    if( !p_libvlc )
586 587 588 589
    {
        return VLC_ENOOBJ;
    }

590
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
591 592 593

    if( !p_input )
    {
594
        if( i_object ) vlc_object_release( p_libvlc );
595 596 597 598 599 600 601 602
        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 );

603
    if( i_object ) vlc_object_release( p_libvlc );
604
    return val.f_float / INPUT_RATE_DEFAULT;
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
}

/**
 * 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;
620
    libvlc_int_t *p_libvlc = vlc_current_object( i_object );
621 622

    /* Check that the handle is valid */
623
    if( !p_libvlc )
624 625 626 627
    {
        return VLC_ENOOBJ;
    }

628
    p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
629 630 631

    if( !p_input )
    {
632
        if( i_object ) vlc_object_release( p_libvlc );
633 634 635 636 637 638 639 640
        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 );

641
    if( i_object ) vlc_object_release( p_libvlc );
642
    return val.f_float / INPUT_RATE_DEFAULT;
643 644 645 646 647 648 649 650 651 652 653 654 655
}

/**
 * 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 )
{
656
    (void)i_object;
657 658
    printf( "This function is deprecated and should not be used anymore" );
    return -1;
659
}
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
660

661
/**
Clément Stenac's avatar
Clément Stenac committed
662
 * Total number of items in the playlist
663 664 665 666 667 668 669
 *
 * \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
670
    LIBVLC_PLAYLIST_FUNC;
Clément Stenac's avatar
Clément Stenac committed
671
    i_size = p_libvlc->p_playlist->items.i_size;
Clément Stenac's avatar
Clément Stenac committed
672
    LIBVLC_PLAYLIST_FUNC_END;
673 674 675 676
    return i_size;
}

/**
Clément Stenac's avatar
Clément Stenac committed
677
 * Go to next playlist item
678 679 680 681 682
 * \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
683 684 685
    LIBVLC_PLAYLIST_FUNC;
    playlist_Next( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
686 687 688 689
    return VLC_SUCCESS;
}

/**
Clément Stenac's avatar
Clément Stenac committed
690
 * Go to previous playlist item
691 692 693 694 695
 * \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
696 697 698
    LIBVLC_PLAYLIST_FUNC;
    playlist_Prev( p_libvlc->p_playlist );
    LIBVLC_PLAYLIST_FUNC_END;
699
    return VLC_SUCCESS;
700 701
}

Clément Stenac's avatar
Clément Stenac committed
702 703 704
/**
 * Empty the playlist
 */
705
int VLC_PlaylistClear( int i_object )
706
{
Clément Stenac's avatar
Clément Stenac committed
707
    LIBVLC_PLAYLIST_FUNC;
708
    playlist_Clear( p_libvlc->p_playlist, VLC_TRUE );
Clément Stenac's avatar
Clément Stenac committed
709
    LIBVLC_PLAYLIST_FUNC_END;
710
    return VLC_SUCCESS;
711 712
}

713 714 715 716 717 718 719 720 721
/**
 * 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 )
{
722
    audio_volume_t i_vol = 0;
Clément Stenac's avatar
Clément Stenac committed
723
    LIBVLC_FUNC;
724

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

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

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

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