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 *****************************************************************************/
40 #include "control/libvlc_internal.h"
42 #include <vlc_playlist.h>
47 /*****************************************************************************
48 * VLC_Version: return the libvlc version.
49 *****************************************************************************
50 * This function returns full version string (numeric version and codename).
51 *****************************************************************************/
52 char const * VLC_Version( void )
54 return VERSION_MESSAGE;
57 /*****************************************************************************
58 * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain,
59 * VLC_Compiler, VLC_Changeset
60 *****************************************************************************/
61 #define DECLARE_VLC_VERSION( func, var ) \
62 char const * VLC_##func ( void ) \
67 DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
68 DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
69 DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
70 DECLARE_VLC_VERSION( Compiler, COMPILER );
72 #ifndef HAVE_SHARED_LIBVLC
73 extern const char psz_vlc_changeset[];
74 char const * VLC_Changeset( void )
76 return psz_vlc_changeset;
80 /*****************************************************************************
81 * VLC_Error: strerror() equivalent
82 *****************************************************************************
83 * This function returns full version string (numeric version and codename).
84 *****************************************************************************/
85 char const * VLC_Error( int i_err )
87 return vlc_error( i_err );
90 /*****************************************************************************
91 * VLC_Create: allocate a libvlc instance and intialize global libvlc stuff if needed
92 *****************************************************************************
93 * This function allocates a libvlc instance and returns a negative value
94 * in case of failure. Also, the thread system is initialized.
95 *****************************************************************************/
96 int VLC_Create( void )
98 libvlc_int_t *p_object = libvlc_InternalCreate();
99 if( p_object ) return p_object->i_object_id;
103 #define LIBVLC_FUNC \
104 libvlc_int_t * p_libvlc = vlc_current_object( i_object ); \
105 if( !p_libvlc ) return VLC_ENOOBJ;
106 #define LIBVLC_FUNC_END \
107 if( i_object ) vlc_object_release( p_libvlc );
110 /*****************************************************************************
111 * VLC_Init: initialize a libvlc instance
112 *****************************************************************************
113 * This function initializes a previously allocated libvlc instance:
115 * - gettext initialization
116 * - message queue, module bank and playlist initialization
117 * - configuration and commandline parsing
118 *****************************************************************************/
119 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
123 i_ret = libvlc_InternalInit( p_libvlc, i_argc, ppsz_argv );
128 /*****************************************************************************
129 * VLC_AddIntf: add an interface
130 *****************************************************************************
131 * This function opens an interface plugin and runs it. If b_block is set
132 * to 0, VLC_AddIntf will return immediately and let the interface run in a
133 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
134 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
135 * the playlist when it is completely initialised.
136 *****************************************************************************/
137 int VLC_AddIntf( int i_object, char const *psz_module,
138 vlc_bool_t b_block, vlc_bool_t b_play )
142 i_ret = libvlc_InternalAddIntf( p_libvlc, psz_module, b_block, b_play,
149 /*****************************************************************************
150 * VLC_Die: ask vlc to die.
151 *****************************************************************************
152 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
153 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
154 *****************************************************************************/
155 int VLC_Die( int i_object )
158 p_libvlc->b_die = VLC_TRUE;
163 /*****************************************************************************
164 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
165 *****************************************************************************/
166 int VLC_CleanUp( int i_object )
170 i_ret = libvlc_InternalCleanup( p_libvlc );
175 /*****************************************************************************
176 * VLC_Destroy: Destroy everything.
177 *****************************************************************************
178 * This function requests the running threads to finish, waits for their
179 * termination, and destroys their structure.
180 *****************************************************************************/
181 int VLC_Destroy( int i_object )
184 return libvlc_InternalDestroy( p_libvlc, i_object ? VLC_TRUE : VLC_FALSE );
187 /*****************************************************************************
188 * VLC_VariableSet: set a vlc variable
189 *****************************************************************************/
190 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
195 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
196 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
197 if( !strncmp( psz_var, "conf::", 6 ) )
199 module_config_t *p_item;
200 char const *psz_newvar = psz_var + 6;
202 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
206 switch( p_item->i_type )
208 case CONFIG_ITEM_BOOL:
209 config_PutInt( p_libvlc, psz_newvar, value.b_bool );
211 case CONFIG_ITEM_INTEGER:
212 config_PutInt( p_libvlc, psz_newvar, value.i_int );
214 case CONFIG_ITEM_FLOAT:
215 config_PutFloat( p_libvlc, psz_newvar, value.f_float );
218 config_PutPsz( p_libvlc, psz_newvar, value.psz_string );
221 if( i_object ) vlc_object_release( p_libvlc );
226 i_ret = var_Set( p_libvlc, psz_var, value );
232 /*****************************************************************************
233 * VLC_VariableGet: get a vlc variable
234 *****************************************************************************/
235 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
239 i_ret = var_Get( p_libvlc , psz_var, p_value );
244 /*****************************************************************************
245 * VLC_VariableType: get a vlc variable type
246 *****************************************************************************/
247 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
251 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
252 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
253 if( !strncmp( psz_var, "conf::", 6 ) )
255 module_config_t *p_item;
256 char const *psz_newvar = psz_var + 6;
258 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
262 switch( p_item->i_type )
264 case CONFIG_ITEM_BOOL:
265 i_type = VLC_VAR_BOOL;
267 case CONFIG_ITEM_INTEGER:
268 i_type = VLC_VAR_INTEGER;
270 case CONFIG_ITEM_FLOAT:
271 i_type = VLC_VAR_FLOAT;
274 i_type = VLC_VAR_STRING;
282 i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
294 #define LIBVLC_PLAYLIST_FUNC \
295 libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
296 if( !p_libvlc || !p_libvlc->p_playlist ) return VLC_ENOOBJ; \
297 vlc_object_yield( p_libvlc->p_playlist );
299 #define LIBVLC_PLAYLIST_FUNC_END \
300 vlc_object_release( p_libvlc->p_playlist ); \
301 if( i_object ) vlc_object_release( p_libvlc );
303 /*****************************************************************************
304 * VLC_AddTarget: adds a target for playing.
305 *****************************************************************************
306 * This function adds psz_target to the playlist
307 *****************************************************************************/
309 int VLC_AddTarget( int i_object, char const *psz_target,
310 char const **ppsz_options, int i_options,
311 int i_mode, int i_pos )
314 LIBVLC_PLAYLIST_FUNC;
315 i_err = playlist_AddExt( p_libvlc->p_playlist, psz_target,
316 NULL, i_mode, i_pos, -1,
317 ppsz_options, i_options, VLC_TRUE );
318 LIBVLC_PLAYLIST_FUNC_END;
322 /*****************************************************************************
323 * VLC_Play: play the playlist
324 *****************************************************************************/
325 int VLC_Play( int i_object )
327 LIBVLC_PLAYLIST_FUNC;
328 playlist_Play( p_libvlc->p_playlist );
329 LIBVLC_PLAYLIST_FUNC_END;
333 /*****************************************************************************
334 * VLC_Pause: toggle pause
335 *****************************************************************************/
336 int VLC_Pause( int i_object )
338 LIBVLC_PLAYLIST_FUNC;
339 playlist_Pause( p_libvlc->p_playlist );
340 LIBVLC_PLAYLIST_FUNC_END;
344 /*****************************************************************************
345 * VLC_Stop: stop playback
346 *****************************************************************************/
347 int VLC_Stop( int i_object )
349 LIBVLC_PLAYLIST_FUNC;
350 playlist_Stop( p_libvlc->p_playlist );
351 LIBVLC_PLAYLIST_FUNC_END;
355 /*****************************************************************************
356 * VLC_IsPlaying: Query for Playlist Status
357 *****************************************************************************/
358 vlc_bool_t VLC_IsPlaying( int i_object )
360 vlc_bool_t b_playing;
362 LIBVLC_PLAYLIST_FUNC;
363 if( p_libvlc->p_playlist->p_input )
366 var_Get( p_libvlc->p_playlist->p_input, "state", &val );
367 b_playing = ( val.i_int == PLAYING_S );
371 b_playing = playlist_IsPlaying( p_libvlc->p_playlist );
373 LIBVLC_PLAYLIST_FUNC_END;
378 * Get the current position in a input
380 * Return the current position as a float
381 * \note For some inputs, this will be unknown.
383 * \param i_object a vlc object id
384 * \return a float in the range of 0.0 - 1.0
386 float VLC_PositionGet( int i_object )
388 input_thread_t *p_input;
392 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
396 if( i_object ) vlc_object_release( p_libvlc );
400 var_Get( p_input, "position", &val );
401 vlc_object_release( p_input );
408 * Set the current position in a input
410 * Set the current position in a input and then return
411 * the current position as a float.
412 * \note For some inputs, this will be unknown.
414 * \param i_object a vlc object id
415 * \param i_position a float in the range of 0.0 - 1.0
416 * \return a float in the range of 0.0 - 1.0
418 float VLC_PositionSet( int i_object, float i_position )
420 input_thread_t *p_input;
422 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
424 /* Check that the handle is valid */
430 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
434 if( i_object ) vlc_object_release( p_libvlc );
438 val.f_float = i_position;
439 var_Set( p_input, "position", val );
440 var_Get( p_input, "position", &val );
441 vlc_object_release( p_input );
443 if( i_object ) vlc_object_release( p_libvlc );
448 * Get the current position in a input
450 * Return the current position in seconds from the start.
451 * \note For some inputs, this will be unknown.
453 * \param i_object a vlc object id
454 * \return the offset from 0:00 in seconds
456 int VLC_TimeGet( int i_object )
458 input_thread_t *p_input;
460 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
462 /* Check that the handle is valid */
468 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
472 if( i_object ) vlc_object_release( p_libvlc );
476 var_Get( p_input, "time", &val );
477 vlc_object_release( p_input );
479 if( i_object ) vlc_object_release( p_libvlc );
480 return val.i_time / 1000000;
484 * Seek to a position in the current input
486 * Seek i_seconds in the current input. If b_relative is set,
487 * then the seek will be relative to the current position, otherwise
488 * it will seek to i_seconds from the beginning of the input.
489 * \note For some inputs, this will be unknown.
491 * \param i_object a vlc object id
492 * \param i_seconds seconds from current position or from beginning of input
493 * \param b_relative seek relative from current position
494 * \return VLC_SUCCESS on success
496 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
498 input_thread_t *p_input;
500 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
502 /* Check that the handle is valid */
508 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
512 if( i_object ) vlc_object_release( p_libvlc );
518 val.i_time = i_seconds;
519 val.i_time = val.i_time * 1000000L;
520 var_Set( p_input, "time-offset", val );
524 val.i_time = i_seconds;
525 val.i_time = val.i_time * 1000000L;
526 var_Set( p_input, "time", val );
528 vlc_object_release( p_input );
530 if( i_object ) vlc_object_release( p_libvlc );
535 * Get the total length of a input
537 * Return the total length in seconds from the current input.
538 * \note For some inputs, this will be unknown.
540 * \param i_object a vlc object id
541 * \return the length in seconds
543 int VLC_LengthGet( int i_object )
545 input_thread_t *p_input;
547 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
549 /* Check that the handle is valid */
555 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
559 if( i_object ) vlc_object_release( p_libvlc );
563 var_Get( p_input, "length", &val );
564 vlc_object_release( p_input );
566 if( i_object ) vlc_object_release( p_libvlc );
567 return val.i_time / 1000000L;
571 * Play the input faster than realtime
573 * 2x, 4x, 8x faster than realtime
574 * \note For some inputs, this will be impossible.
576 * \param i_object a vlc object id
577 * \return the current speedrate
579 float VLC_SpeedFaster( int i_object )
581 input_thread_t *p_input;
583 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
585 /* Check that the handle is valid */
591 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
595 if( i_object ) vlc_object_release( p_libvlc );
599 val.b_bool = VLC_TRUE;
600 var_Set( p_input, "rate-faster", val );
601 var_Get( p_input, "rate", &val );
602 vlc_object_release( p_input );
604 if( i_object ) vlc_object_release( p_libvlc );
605 return val.f_float / INPUT_RATE_DEFAULT;
609 * Play the input slower than realtime
611 * 1/2x, 1/4x, 1/8x slower than realtime
612 * \note For some inputs, this will be impossible.
614 * \param i_object a vlc object id
615 * \return the current speedrate
617 float VLC_SpeedSlower( int i_object )
619 input_thread_t *p_input;
621 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
623 /* Check that the handle is valid */
629 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
633 if( i_object ) vlc_object_release( p_libvlc );
637 val.b_bool = VLC_TRUE;
638 var_Set( p_input, "rate-slower", val );
639 var_Get( p_input, "rate", &val );
640 vlc_object_release( p_input );
642 if( i_object ) vlc_object_release( p_libvlc );
643 return val.f_float / INPUT_RATE_DEFAULT;
647 * Return the current playlist item
649 * Returns the index of the playlistitem that is currently selected for play.
650 * This is valid even if nothing is currently playing.
652 * \param i_object a vlc object id
653 * \return the current index
655 int VLC_PlaylistIndex( int i_object )
657 printf( "This function is deprecated and should not be used anymore" );
662 * Total number of items in the playlist
664 * \param i_object a vlc object id
665 * \return amount of playlist items
667 int VLC_PlaylistNumberOfItems( int i_object )
670 LIBVLC_PLAYLIST_FUNC;
671 i_size = p_libvlc->p_playlist->items.i_size;
672 LIBVLC_PLAYLIST_FUNC_END;
677 * Go to next playlist item
678 * \param i_object a vlc object id
679 * \return VLC_SUCCESS on success
681 int VLC_PlaylistNext( int i_object )
683 LIBVLC_PLAYLIST_FUNC;
684 playlist_Next( p_libvlc->p_playlist );
685 LIBVLC_PLAYLIST_FUNC_END;
690 * Go to previous playlist item
691 * \param i_object a vlc object id
692 * \return VLC_SUCCESS on success
694 int VLC_PlaylistPrev( int i_object )
696 LIBVLC_PLAYLIST_FUNC;
697 playlist_Prev( p_libvlc->p_playlist );
698 LIBVLC_PLAYLIST_FUNC_END;
705 int VLC_PlaylistClear( int i_object )
707 LIBVLC_PLAYLIST_FUNC;
708 playlist_Clear( p_libvlc->p_playlist, VLC_TRUE );
709 LIBVLC_PLAYLIST_FUNC_END;
716 * \param i_object a vlc object id
717 * \param i_volume something in a range from 0-200
718 * \return the new volume (range 0-200 %)
720 int VLC_VolumeSet( int i_object, int i_volume )
722 audio_volume_t i_vol = 0;
725 if( i_volume >= 0 && i_volume <= 200 )
727 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
728 aout_VolumeSet( p_libvlc, i_vol );
731 return i_vol * 200 / AOUT_VOLUME_MAX;
735 * Get the current volume
737 * Retrieve the current volume.
739 * \param i_object a vlc object id
740 * \return the current volume (range 0-200 %)
742 int VLC_VolumeGet( int i_object )
744 audio_volume_t i_volume;
746 aout_VolumeGet( p_libvlc, &i_volume );
748 return i_volume*200/AOUT_VOLUME_MAX;
752 * Mute/Unmute the volume
754 * \param i_object a vlc object id
755 * \return VLC_SUCCESS on success
757 int VLC_VolumeMute( int i_object )
760 aout_VolumeMute( p_libvlc, NULL );
765 /*****************************************************************************
766 * VLC_FullScreen: toggle fullscreen mode
767 *****************************************************************************/
768 int VLC_FullScreen( int i_object )
770 vout_thread_t *p_vout;
772 p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
776 if( i_object ) vlc_object_release( p_libvlc );
780 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
781 vlc_object_release( p_vout );