1 /*****************************************************************************
2 * libvlc.c: Implementation of the old libvlc API
3 *****************************************************************************
4 * Copyright (C) 1998-2006 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * 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>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
29 * Pretend we are a builtin module
30 *****************************************************************************/
31 #define MODULE_NAME main
32 #define MODULE_PATH main
35 /*****************************************************************************
37 *****************************************************************************/
39 #include <vlc/input.h>
41 #include <libvlc_internal.h>
43 #include <vlc_error.h>
45 #include "audio_output.h"
46 #include "vlc_video.h"
47 #include "video_output.h"
49 /*****************************************************************************
50 * VLC_Version: return the libvlc version.
51 *****************************************************************************
52 * This function returns full version string (numeric version and codename).
53 *****************************************************************************/
54 char const * VLC_Version( void )
56 return VERSION_MESSAGE;
59 /*****************************************************************************
60 * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain,
61 * VLC_Compiler, VLC_Changeset
62 *****************************************************************************/
63 #define DECLARE_VLC_VERSION( func, var ) \
64 char const * VLC_##func ( void ) \
69 DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
70 DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
71 DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
72 DECLARE_VLC_VERSION( Compiler, COMPILER );
74 #ifndef HAVE_SHARED_LIBVLC
75 extern const char psz_vlc_changeset[];
76 char const * VLC_Changeset( void )
78 return psz_vlc_changeset;
82 /*****************************************************************************
83 * VLC_Error: strerror() equivalent
84 *****************************************************************************
85 * This function returns full version string (numeric version and codename).
86 *****************************************************************************/
87 char const * VLC_Error( int i_err )
89 return vlc_error( i_err );
92 /*****************************************************************************
93 * VLC_Create: allocate a libvlc instance and intialize global libvlc stuff if needed
94 *****************************************************************************
95 * This function allocates a libvlc instance and returns a negative value
96 * in case of failure. Also, the thread system is initialized.
97 *****************************************************************************/
98 int VLC_Create( void )
100 libvlc_int_t *p_object = libvlc_InternalCreate();
101 if( p_object ) return p_object->i_object_id;
105 #define LIBVLC_FUNC \
106 libvlc_int_t * p_libvlc = vlc_current_object( i_object ); \
107 if( !p_libvlc ) return VLC_ENOOBJ;
108 #define LIBVLC_FUNC_END \
109 if( i_object ) vlc_object_release( p_libvlc );
112 /*****************************************************************************
113 * VLC_Init: initialize a libvlc instance
114 *****************************************************************************
115 * This function initializes a previously allocated libvlc instance:
117 * - gettext initialization
118 * - message queue, module bank and playlist initialization
119 * - configuration and commandline parsing
120 *****************************************************************************/
121 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
125 i_ret = libvlc_InternalInit( p_libvlc, i_argc, ppsz_argv );
130 /*****************************************************************************
131 * VLC_AddIntf: add an interface
132 *****************************************************************************
133 * This function opens an interface plugin and runs it. If b_block is set
134 * to 0, VLC_AddIntf will return immediately and let the interface run in a
135 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
136 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
137 * the playlist when it is completely initialised.
138 *****************************************************************************/
139 int VLC_AddIntf( int i_object, char const *psz_module,
140 vlc_bool_t b_block, vlc_bool_t b_play )
144 i_ret = libvlc_InternalAddIntf( p_libvlc, psz_module, b_block, b_play,
151 /*****************************************************************************
152 * VLC_Die: ask vlc to die.
153 *****************************************************************************
154 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
155 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
156 *****************************************************************************/
157 int VLC_Die( int i_object )
160 p_libvlc->b_die = VLC_TRUE;
165 /*****************************************************************************
166 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
167 *****************************************************************************/
168 int VLC_CleanUp( int i_object )
172 i_ret = libvlc_InternalCleanup( p_libvlc );
177 /*****************************************************************************
178 * VLC_Destroy: Destroy everything.
179 *****************************************************************************
180 * This function requests the running threads to finish, waits for their
181 * termination, and destroys their structure.
182 *****************************************************************************/
183 int VLC_Destroy( int i_object )
186 return libvlc_InternalDestroy( p_libvlc, i_object ? VLC_TRUE : VLC_FALSE );
189 /*****************************************************************************
190 * VLC_VariableSet: set a vlc variable
191 *****************************************************************************/
192 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
197 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
198 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
199 if( !strncmp( psz_var, "conf::", 6 ) )
201 module_config_t *p_item;
202 char const *psz_newvar = psz_var + 6;
204 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
208 switch( p_item->i_type )
210 case CONFIG_ITEM_BOOL:
211 config_PutInt( p_libvlc, psz_newvar, value.b_bool );
213 case CONFIG_ITEM_INTEGER:
214 config_PutInt( p_libvlc, psz_newvar, value.i_int );
216 case CONFIG_ITEM_FLOAT:
217 config_PutFloat( p_libvlc, psz_newvar, value.f_float );
220 config_PutPsz( p_libvlc, psz_newvar, value.psz_string );
223 if( i_object ) vlc_object_release( p_libvlc );
228 i_ret = var_Set( p_libvlc, psz_var, value );
234 /*****************************************************************************
235 * VLC_VariableGet: get a vlc variable
236 *****************************************************************************/
237 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
241 i_ret = var_Get( p_libvlc , psz_var, p_value );
246 /*****************************************************************************
247 * VLC_VariableType: get a vlc variable type
248 *****************************************************************************/
249 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
253 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
254 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
255 if( !strncmp( psz_var, "conf::", 6 ) )
257 module_config_t *p_item;
258 char const *psz_newvar = psz_var + 6;
260 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
264 switch( p_item->i_type )
266 case CONFIG_ITEM_BOOL:
267 i_type = VLC_VAR_BOOL;
269 case CONFIG_ITEM_INTEGER:
270 i_type = VLC_VAR_INTEGER;
272 case CONFIG_ITEM_FLOAT:
273 i_type = VLC_VAR_FLOAT;
276 i_type = VLC_VAR_STRING;
284 i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
296 #define LIBVLC_PLAYLIST_FUNC \
297 libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
298 if( !p_libvlc || !p_libvlc->p_playlist ) return VLC_ENOOBJ; \
299 vlc_object_yield( p_libvlc->p_playlist );
301 #define LIBVLC_PLAYLIST_FUNC_END \
302 vlc_object_release( p_libvlc->p_playlist ); \
303 if( i_object ) vlc_object_release( p_libvlc );
305 /*****************************************************************************
306 * VLC_AddTarget: adds a target for playing.
307 *****************************************************************************
308 * This function adds psz_target to the playlist
309 *****************************************************************************/
311 int VLC_AddTarget( int i_object, char const *psz_target,
312 char const **ppsz_options, int i_options,
313 int i_mode, int i_pos )
316 LIBVLC_PLAYLIST_FUNC;
317 i_err = playlist_PlaylistAddExt( p_libvlc->p_playlist, psz_target,
318 NULL, i_mode, i_pos, -1,
319 ppsz_options, i_options );
320 LIBVLC_PLAYLIST_FUNC_END;
324 /*****************************************************************************
325 * VLC_Play: play the playlist
326 *****************************************************************************/
327 int VLC_Play( int i_object )
329 LIBVLC_PLAYLIST_FUNC;
330 playlist_Play( p_libvlc->p_playlist );
331 LIBVLC_PLAYLIST_FUNC_END;
335 /*****************************************************************************
336 * VLC_Pause: toggle pause
337 *****************************************************************************/
338 int VLC_Pause( int i_object )
340 LIBVLC_PLAYLIST_FUNC;
341 playlist_Pause( p_libvlc->p_playlist );
342 LIBVLC_PLAYLIST_FUNC_END;
346 /*****************************************************************************
347 * VLC_Stop: stop playback
348 *****************************************************************************/
349 int VLC_Stop( int i_object )
351 LIBVLC_PLAYLIST_FUNC;
352 playlist_Stop( p_libvlc->p_playlist );
353 LIBVLC_PLAYLIST_FUNC_END;
357 /*****************************************************************************
358 * VLC_IsPlaying: Query for Playlist Status
359 *****************************************************************************/
360 vlc_bool_t VLC_IsPlaying( int i_object )
362 vlc_bool_t b_playing;
364 LIBVLC_PLAYLIST_FUNC;
365 if( p_libvlc->p_playlist->p_input )
368 var_Get( p_libvlc->p_playlist->p_input, "state", &val );
369 b_playing = ( val.i_int == PLAYING_S );
373 b_playing = playlist_IsPlaying( p_libvlc->p_playlist );
375 LIBVLC_PLAYLIST_FUNC_END;
380 * Get the current position in a input
382 * Return the current position as a float
383 * \note For some inputs, this will be unknown.
385 * \param i_object a vlc object id
386 * \return a float in the range of 0.0 - 1.0
388 float VLC_PositionGet( int i_object )
390 input_thread_t *p_input;
394 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
398 if( i_object ) vlc_object_release( p_libvlc );
402 var_Get( p_input, "position", &val );
403 vlc_object_release( p_input );
410 * Set the current position in a input
412 * Set the current position in a input and then return
413 * the current position as a float.
414 * \note For some inputs, this will be unknown.
416 * \param i_object a vlc object id
417 * \param i_position a float in the range of 0.0 - 1.0
418 * \return a float in the range of 0.0 - 1.0
420 float VLC_PositionSet( int i_object, float i_position )
422 input_thread_t *p_input;
424 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
426 /* Check that the handle is valid */
432 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
436 if( i_object ) vlc_object_release( p_libvlc );
440 val.f_float = i_position;
441 var_Set( p_input, "position", val );
442 var_Get( p_input, "position", &val );
443 vlc_object_release( p_input );
445 if( i_object ) vlc_object_release( p_libvlc );
450 * Get the current position in a input
452 * Return the current position in seconds from the start.
453 * \note For some inputs, this will be unknown.
455 * \param i_object a vlc object id
456 * \return the offset from 0:00 in seconds
458 int VLC_TimeGet( int i_object )
460 input_thread_t *p_input;
462 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
464 /* Check that the handle is valid */
470 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
474 if( i_object ) vlc_object_release( p_libvlc );
478 var_Get( p_input, "time", &val );
479 vlc_object_release( p_input );
481 if( i_object ) vlc_object_release( p_libvlc );
482 return val.i_time / 1000000;
486 * Seek to a position in the current input
488 * Seek i_seconds in the current input. If b_relative is set,
489 * then the seek will be relative to the current position, otherwise
490 * it will seek to i_seconds from the beginning of the input.
491 * \note For some inputs, this will be unknown.
493 * \param i_object a vlc object id
494 * \param i_seconds seconds from current position or from beginning of input
495 * \param b_relative seek relative from current position
496 * \return VLC_SUCCESS on success
498 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
500 input_thread_t *p_input;
502 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
504 /* Check that the handle is valid */
510 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
514 if( i_object ) vlc_object_release( p_libvlc );
520 val.i_time = i_seconds;
521 val.i_time = val.i_time * 1000000L;
522 var_Set( p_input, "time-offset", val );
526 val.i_time = i_seconds;
527 val.i_time = val.i_time * 1000000L;
528 var_Set( p_input, "time", val );
530 vlc_object_release( p_input );
532 if( i_object ) vlc_object_release( p_libvlc );
537 * Get the total length of a input
539 * Return the total length in seconds from the current input.
540 * \note For some inputs, this will be unknown.
542 * \param i_object a vlc object id
543 * \return the length in seconds
545 int VLC_LengthGet( int i_object )
547 input_thread_t *p_input;
549 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
551 /* Check that the handle is valid */
557 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
561 if( i_object ) vlc_object_release( p_libvlc );
565 var_Get( p_input, "length", &val );
566 vlc_object_release( p_input );
568 if( i_object ) vlc_object_release( p_libvlc );
569 return val.i_time / 1000000L;
573 * Play the input faster than realtime
575 * 2x, 4x, 8x faster than realtime
576 * \note For some inputs, this will be impossible.
578 * \param i_object a vlc object id
579 * \return the current speedrate
581 float VLC_SpeedFaster( int i_object )
583 input_thread_t *p_input;
585 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
587 /* Check that the handle is valid */
593 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
597 if( i_object ) vlc_object_release( p_libvlc );
601 val.b_bool = VLC_TRUE;
602 var_Set( p_input, "rate-faster", val );
603 var_Get( p_input, "rate", &val );
604 vlc_object_release( p_input );
606 if( i_object ) vlc_object_release( p_libvlc );
607 return val.f_float / INPUT_RATE_DEFAULT;
611 * Play the input slower than realtime
613 * 1/2x, 1/4x, 1/8x slower than realtime
614 * \note For some inputs, this will be impossible.
616 * \param i_object a vlc object id
617 * \return the current speedrate
619 float VLC_SpeedSlower( int i_object )
621 input_thread_t *p_input;
623 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
625 /* Check that the handle is valid */
631 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
635 if( i_object ) vlc_object_release( p_libvlc );
639 val.b_bool = VLC_TRUE;
640 var_Set( p_input, "rate-slower", val );
641 var_Get( p_input, "rate", &val );
642 vlc_object_release( p_input );
644 if( i_object ) vlc_object_release( p_libvlc );
645 return val.f_float / INPUT_RATE_DEFAULT;
649 * Return the current playlist item
651 * Returns the index of the playlistitem that is currently selected for play.
652 * This is valid even if nothing is currently playing.
654 * \param i_object a vlc object id
655 * \return the current index
657 int VLC_PlaylistIndex( int i_object )
659 printf( "This function is deprecated and should not be used anymore" );
664 * Total number of items in the playlist
666 * \param i_object a vlc object id
667 * \return amount of playlist items
669 int VLC_PlaylistNumberOfItems( int i_object )
672 LIBVLC_PLAYLIST_FUNC;
673 i_size = p_libvlc->p_playlist->items.i_size;
674 LIBVLC_PLAYLIST_FUNC_END;
679 * Go to next playlist item
680 * \param i_object a vlc object id
681 * \return VLC_SUCCESS on success
683 int VLC_PlaylistNext( int i_object )
685 LIBVLC_PLAYLIST_FUNC;
686 playlist_Next( p_libvlc->p_playlist );
687 LIBVLC_PLAYLIST_FUNC_END;
692 * Go to previous playlist item
693 * \param i_object a vlc object id
694 * \return VLC_SUCCESS on success
696 int VLC_PlaylistPrev( int i_object )
698 LIBVLC_PLAYLIST_FUNC;
699 playlist_Prev( p_libvlc->p_playlist );
700 LIBVLC_PLAYLIST_FUNC_END;
707 int VLC_PlaylistClear( int i_object )
709 LIBVLC_PLAYLIST_FUNC;
710 playlist_Clear( p_libvlc->p_playlist );
711 LIBVLC_PLAYLIST_FUNC_END;
718 * \param i_object a vlc object id
719 * \param i_volume something in a range from 0-200
720 * \return the new volume (range 0-200 %)
722 int VLC_VolumeSet( int i_object, int i_volume )
724 audio_volume_t i_vol = 0;
727 if( i_volume >= 0 && i_volume <= 200 )
729 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
730 aout_VolumeSet( p_libvlc, i_vol );
733 return i_vol * 200 / AOUT_VOLUME_MAX;
737 * Get the current volume
739 * Retrieve the current volume.
741 * \param i_object a vlc object id
742 * \return the current volume (range 0-200 %)
744 int VLC_VolumeGet( int i_object )
746 audio_volume_t i_volume;
748 aout_VolumeGet( p_libvlc, &i_volume );
750 return i_volume*200/AOUT_VOLUME_MAX;
754 * Mute/Unmute the volume
756 * \param i_object a vlc object id
757 * \return VLC_SUCCESS on success
759 int VLC_VolumeMute( int i_object )
762 aout_VolumeMute( p_libvlc, NULL );
767 /*****************************************************************************
768 * VLC_FullScreen: toggle fullscreen mode
769 *****************************************************************************/
770 int VLC_FullScreen( int i_object )
772 vout_thread_t *p_vout;
774 p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
778 if( i_object ) vlc_object_release( p_libvlc );
782 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
783 vlc_object_release( p_vout );